요약
master 브랜치에서 작업중 git pull
명령을 실행했을 때 저장소와 브랜치를 명시하라는 에러를 만나면 .git/config에 다음과 같이 설정하라.
[branch "master"]
remote = origin
merge = refs/heads/master
설명
git pull
을 실행했을 때, 어떤 경우엔 군말없이 merge까지 잘 끝내지만, 어떤 경우엔 다음과 같은 메시지를 뱉으면서 실패하기도 한다.
You asked me to pull without telling me which branch you
want to merge with, and 'branch.master.merge' in
your configuration file does not tell me, either. Please
specify which branch you want to use on the command line and
try again (e.g. 'git pull <repository> <refspec>').
See git-pull(1) for details.
If you often merge with the same branch, you may want to
use something like the following in your configuration file:
[branch "master"]
remote = <nickname>
merge = <remote-ref>
[remote "<nickname>"]
url = <url>
fetch = <refspec>
See git-config(1) for details.
git clone
으로 기존의 저장소를 복제한 후 작업을 하고 있었다면, 이런 메시지를 만날 일은 없을 것이다. 그러나 직접 git init
으로 바로 로컬에 저장소를 만들어 작업하다가 나중에 git remote add
로 원격저장소를 추가하여 작업하고 있다면 이런 메시지를 만날 수 있다.
원래 git pull
명령은 git pull origin master
이런 식으로 저장소와 브랜치를 모두 정확히 명기하는 것이 맞다. 좀 더 정확히 하자면, git pull origin master:master
식으로 어떤 저장소에 내 어떤 브랜치를 그 저장소의 어떤 브랜치에 머지할 것인지(master:master) 알려줘야 한다.
그러나 이런 식으로 매번 일일이 인자를 적어주는 것은 번거롭기 떄문에, git pull
만 해도 알아서 자동으로 동작하도록 .git/config 파일에 설정할 수 있다.
[branch "master"]
remote = origin
merge = refs/heads/master
위 설정의 의미는, 현재 로컬 브랜치 “master”에 대해 기본 원격 저장소는 origin이고 기본 merge 브랜치는 원격 저장소의 refs/heads/master 임을 의미한다. 다시 말해, 위와 같은 설정이 되어있고 현재 브랜치가 master일 때, git pull
을 실행하면 git pull origin master:master
와 동일하게 동작한다. (git clone
명령은 저장소를 복제할 때 위의 설정을 알아서 해 준다)
설정이 귀찮으면 git push
할 때 -u 옵션을 줘서 자동으로 설정이 되도록 할 수도 있다. (github에서는 이 방법을 권한다)
$ git remote add origin git://example.com/git.git/
$ git push -u origin master