아래와 같이 브랜치 이름만 주었을 경우 no upstream 에러가 발생한다
# git push branch_name
fatal: The current branch master has no upstream branch.
To push the current branch and set the remote as upstream, use
git push --set-upstream origin master
에러 메시지에서 "--set-upstream" 옵션으로 origin을 upstream으로 지정하는 것을 권장하고 있다.
실제로는 "--set-upstream" 옵션없이 origin만 추가해도 push가 정상적으로 진행된다.
그럼 origin, upstream, --set-upstream 옵션 이게 다 뭘까?
둘 다 remote repository, 즉 원격 저장소를 나타내는 이름이다.
git이 자동으로 만드는 정해져있는 이름이다.
그럼 origin과 upstream이 같은 의미인건가?
그런데 난 origin을 지정한 적이 없는데?
C/C++식으로 비유하면 origin과 upstream이라는 포인터라고 보면 된다.
origin은 어느 remote repository를 가리킬지 자동으로 정해진다.
내가 코드를 local 저장소에 복제(clone)할 때
origin은 소스가 된 remote repository를 가리키도록 자동으로 셋팅된다.
그러나 upstream은 어느 레포지토리를 가리킬지 정해줘야 한다.
보통은 내가 복제(fork)해온 원본 레포지토리로 설정해서 사용한다고 하는데,
필요에 따라 어느 remote와 연결할지 정해서 사용하는 것이므로
다른 관련있는 remote가 될 수도, origin과 같을 수도 있다.
에러 메시지를 다시 보자.
# git push branch_name
fatal: The current branch master has no upstream branch.
To push the current branch and set the remote as upstream, use
git push --set-upstream origin master
위의 no upstream 에러 메시지는
local의 작업 공간에서 수정한 코드를 upstream branch에 push 해야 하는데 upstream이 어딘지 모르니까 정해주라는 뜻이다.
그래서 에러 메시지대로 "--set-upstream" 옵션을 사용하면
push하면서 upstream 설정도 해버릴 수 있다.
upstream을 설정하고나면 이렇게만 입력해도 push가 진행된다.
# git push branch_name
물론 "--set-upstream" 없이 바로 origin을 써주면 upstream은 비워두면서, git push를 어디에 해야할지 알려줬으므로 push가 잘 진행된다.