달력

52024  이전 다음

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31

git init --bare 이용

Tool/git 2010. 4. 23. 03:06
git repository에 소스가 있는데 이를 clone 해서 변경하고 push 하면 문제가 있다는 것을
이전 글에서 확인했다. (이전 글 --> http://www.neodelicious.com/entry/git-init-bare-1)

이번에는 --bare 옵션을 통해 위의 문제를 해결하는 방법을 설명하고자 한다.

글을 쓰기에 앞서 이전 글에서도 밝혔지만, 아래 웹 페이즈에서 많은 정보를 얻었음을 밝힌다.
http://stackoverflow.com/questions/738154/what-does-git-updating-currently-checked-out-branch-warning-mean

위 링크의 글 상단에 또 다른 링크 How to publish a Git repository를 출처로 bare repository 를 설명하고 있다.

이 bare repository 및 관련 내용을 간단히 번역하면,
우선 bare repository 는 git dababase 만 있고 소스 파일(working copy of code) 없는 것을 의미한다.
만약 bare repository가 아닌 소스 파일이 있는 git repository(non-bare repo)에 git push 하게 되면
HEAD가 git index, 소스 사이에  sync 문제가 발생하므로
(이게 이전 글 http://www.neodelicious.com/entry/git-init-bare-1 에서 확인한 사항이다.)
항상 bare repository에 git push 해야 한다.

그럼 위에서 권고한대로 우선 아무 것도 없는 디렉토리에서 git init --bare로 초기화해보자.
/.git 아래에 숨겨졌던 git database 파일들이 현재 디렉토리에 보이는 것을 확인했다.

jaewon@jaewon-laptop:~/work/study/tool/git$ mkdir remote_bare
jaewon@jaewon-laptop:~/work/study/tool/git$ cd remote_bare/
jaewon@jaewon-laptop:~/work/study/tool/git/remote_bare$ git init --bare
Initialized empty Git repository in /home/jaewon/work/study/tool/git/remote_bare/
jaewon@jaewon-laptop:~/work/study/tool/git/remote_bare$ ls
branches  config  description  HEAD  hooks  info  objects  refs

그 다음에 위의 bare repository를 git clone 하고 새 파일을 생성 및 수정하고 local에 git commit 했다.

jaewon@jaewon-laptop:~/work/study/tool/git/remote_bare$ cd ..
jaewon@jaewon-laptop:~/work/study/tool/git$ git clone ./remote_bare/ ./local
Initialized empty Git repository in /home/jaewon/work/study/tool/git/local/.git/
warning: You appear to have cloned an empty repository.
jaewon@jaewon-laptop:~/work/study/tool/git$ cd local/
jaewon@jaewon-laptop:~/work/study/tool/git/local$ echo "initial" > ./1.txt
jaewon@jaewon-laptop:~/work/study/tool/git/local$ git add 1.txt
jaewon@jaewon-laptop:~/work/study/tool/git/local$ git commit -a -m '1st'
[master (root-commit) 6833fa2] 1st
 1 files changed, 1 insertions(+), 0 deletions(-)
 create mode 100644 1.txt

그 다음에 bare repository에 git push를 하기 위해 git push 했는데,
다음과 같이 push의 기본 설정이 안 되어 있다고 해서 오류가 발생했다.

jaewon@jaewon-laptop:~/work/study/tool/git/local$ git push
warning: You did not specify any refspecs to push, and the current remote
warning: has not configured any push refspecs. The default action in this
warning: case is to push all matching refspecs, that is, all branches
warning: that exist both locally and remotely will be updated.  This may
warning: not necessarily be what you want to happen.
warning:
warning: You can specify what action you want to take in this case, and
warning: avoid seeing this message again, by configuring 'push.default' to:
warning:   'nothing'  : Do not push anything
warning:   'matching' : Push all matching branches (default)
warning:   'tracking' : Push the current branch to whatever it is tracking
warning:   'current'  : Push the current branch
No refs in common and none specified; doing nothing.
Perhaps you should specify a branch such as 'master'.
fatal: The remote end hung up unexpectedly
error: failed to push some refs to '/home/jaewon/work/study/tool/git/./remote_bare/'

여러 가지 설정이 있을 수 있겠지만, 나는 일단 tracking 방식을 기본으로 설정하고자
git config push.default tracking 과 같이 입력했다.
그리고 push를 정상적으로 할 수 있었다.

jaewon@jaewon-laptop:~/work/study/tool/git/local$ git config push.default tracking
jaewon@jaewon-laptop:~/work/study/tool/git/local$ git push
Counting objects: 3, done.
Writing objects: 100% (3/3), 210 bytes, done.
Total 3 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
To /home/jaewon/work/study/tool/git/./remote_bare/
 * [new branch]      master -> master

참고적으로 소스 파일이 있는 git repository(non-bare repo)에 git push 해서 발생하는 문제는
이후 git 버전에서 금지될 것 이라고 한다.

또한 기존에 소스 파일이 있는 git repository(non-bare repo)을 clone 하려고 할 경우,
git clone --bare 와 같이 --bare 옵션을 주면 새 repo가 bare repo 가 된다.
git clone --bare 를 아래와 같이 확인했다.

jaewon@jaewon-laptop:~/work/study/tool/git/remote_src$ cd ..
jaewon@jaewon-laptop:~/work/study/tool/git$ git clone --bare ./remote_src/ ./remote_src_bare
Initialized empty Git repository in /home/jaewon/work/study/tool/git/remote_src_bare/
jaewon@jaewon-laptop:~/work/study/tool/git$ cd remote_src_bare/
jaewon@jaewon-laptop:~/work/study/tool/git/remote_src_bare$ ls
branches  config  description  HEAD  hooks  info  objects  packed-refs  refs
jaewon@jaewon-laptop:~/work/study/tool/git/remote_src_bare$ git log
commit 979521d7978f7a26c989047bae7806466353ad61
Author: jaewon <jaewon@jaewon-laptop.(none)>
Date:   Fri Apr 23 02:44:44 2010 +0900
    2nd
commit fc2d23fb93c972c3f48a75f9bf7be7de6a5d5ea3
Author: jaewon <jaewon@jaewon-laptop.(none)>
Date:   Fri Apr 23 02:42:48 2010 +0900
    initial

그런데 non-bare repo 에 push 하더라도 non-bare repo 의 code를 그대로 이용하지 않고
clone 한 후 pull 로 이용하면 문제가 없었다.
그래도 새로 만들 때는 bare 로 하는 게 좋겠다.

그밖에 Using Git to manage a web siteHow to publish a Git repository
hooks/post-receive 파일을 이용해서 git push 되면 자동으로 git checkout -f 되도록 하던데,
자세한 사항은 이해를 못 해서 지금은 넘어가기로 한다.


'Tool > git' 카테고리의 다른 글

git 알면 편한 기능  (0) 2010.11.13
git reference  (0) 2010.07.05
git staic build  (0) 2010.04.27
git init --bare 발단  (0) 2010.04.23
qgit  (0) 2010.04.20
Posted by neodelicious
|