오류 상황
git pull을 입력했는데,
"There is no tracking information for the current branch.Please specify which branch you want to merge with" 메시지가 나온다!

혹여나 git clone이 아닌 git init + git pull 조합으로 원격 저장소(git)에 있는 프로젝트를 로컬로 받아오려고 시도한 경우 해당 해결 방법으로 해결을 시도해보자.
✅
git clone 명령어를 사용하여 원격 저장소를 로컬에 복제(clone)했다면, 원격 저장소의 기본 브랜치(보통 master나main 브랜치)가 로컬 브랜치와 자동으로 연결(tracking)된다.
✅
git init을 사용하는 경우 수동으로 원격 브랜치를 로컬 브랜치와 연결해주어야 git pull이 정상적으로 작동
한다.
해결
1. git branch --set-upstream-to=origin/master master
- (응답) Successfully rebased and updated refs/heads/master.
👄 원격 저장소의 master 브랜치를 로컬 master 브랜치의 업스트림 브랜치로 설정하라.
위 명령어는 업스트림 브랜치를 지정하는 명령어이다. 나는 원격 저장소의 master 브랜치를 로컬 master 브랜치의 업스트림 브랜치로 지정하고 싶었다. 따라서 origin/master master 로 작성 해주었다.
이와 같이 upstream branch를 설정하지 않고 그냥 git pull을 입력한다면 어떻게 될까?
"There is no tracking information for the current branch.
Please specify which branch you want to merge with."
See git-pull(1) for details.
git pull <remote> <branch>
If you wish to set tracking information for this branch you can do so with:
git branch --set-upstream-to=origin/<branch> master
이러한 오류가 발생하면서 원하는대로 원격 저장소의 내용을 fetch 후 merge해오지 못한다. 따라서 반영해오고 싶은 원격 저장소의 브랜치를 업스트림 브랜치로 지정해주면 된다.
이렇게 원격저장소의 master 브랜치를 로컬 master 브랜치의 업스트림 브랜치로 설정하면 master 로컬 브랜치가 원격 저장소의 master 브랜치를 추적할 수 있게 된다.
이러한 관계를 tracking connection이라고 부르며, 이러한 관계 속에서 원격 저장소의 master 브랜치는 로컬 저장소의 master 브랜치의 업스트림 브랜치라고 묘사한다.
2. git pull --rebase
- (응답) Successfully rebased and updated refs/heads/master.
(성공 🍀)
이제 push를 해보자.
thddm@mungsil MINGW64 /c/springStudy/querydslStudy (master)
$ git push origin master
Enumerating objects: 31, done.
Counting objects: 100% (31/31), done.
Delta compression using up to 8 threads
Compressing objects: 100% (19/19), done.
Writing objects: 100% (30/30), 45.98 KiB | 5.75 MiB/s, done.
Total 30 (delta 1), reused 0 (delta 0), pack-reused 0
remote: Resolving deltas: 100% (1/1), done.
To [https://github.com/mungsil/QueryDSL-study.git](https://github.com/mungsil/QueryDSL-study.git)
0ac0698..2b7d200 master -> master
오류 발생 상황을 되짚어보자
로컬에 깃 저장소를 만들었다.
git init
로컬 저장소에 원격 깃 저장소를 연결하였다.
git remote add origin https://github.com/mungsil/QueryDSL-study.git
원격 저장소의 내용을 반영했다 하려고 했다.
git pull origin
어라, 뭔가 이상하다. ㅇㅋ 원격 저장소 내용 가져왔어! 를 기대했지만, 다른 내용이었다.
Unpacking objects: 100% (3/3), 651 bytes | 65.00 KiB/s, done.
From https://github.com/mungsil/QueryDSL-study
* [new branch] master -> origin/master
You asked to pull from the remote 'origin', but did not specify
a branch. Because this is not the default configured remote
for your current branch, you must specify a branch on the command line.
다시 한 번 느끼지만, git은 메세지로 참 잘 알려준다. 내가 문제지...
You asked to pull from the remote 'origin', but did not specify a branch. Because this is not the default configured remote for your current branch, you must specify a branch on the command line.
라는 말에 주목하자.
그치만 당시의 나는 주목하지 못하고(...) 이를 지나친 후 로컬 저장소에서 작업을 시작했다. 이후 평소 하던 것처럼 git add, commit 명령어를 입력하였다. 그리고 원격 master branch에 작업물을 올리기 위해 git push origin master 명령어를 입력했다.
thddm@mungsil MINGW64 /c/springStudy/querydslStudy (master)
$ git push origin master
To https://github.com/mungsil/QueryDSL-study.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'https://github.com/mungsil/QueryDSL-study.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. If you want to integrate the remote changes,
hint: use 'git pull' before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
오류가 발생했다. push가 안된단다.
이때 git pull 명령어를 입력하면 마침내 해당 포스트의 제목 메시지를 볼 수 있다.
"There is no tracking information for the current branch.
Please specify which branch you want to merge with."
See git-pull(1) for details.
git pull <remote> <branch>
If you wish to set tracking information for this branch you can do so with:
git branch --set-upstream-to=origin/<branch> master
뒤늦게 git pull origin master
를 입력해줘도 안된다.
From https://github.com/mungsil/QueryDSL-study
* branch master -> FETCH_HEAD
fatal: refusing to merge unrelated histories
원격저장소의 master 브랜치 내용을 가져오기는 했으나, "unrelated histories"로 인해 merge는 실패했다는 말이다.
오류 발생 원인
모든 것은 평소와 같았다. 단, 다음 명령어를 입력했을 때 나왔던 git의 안내 메시지를 제외하고는...
git pull origin
You asked to pull from the remote 'origin', but did not specify a branch. Because this is not the default configured remote for your current branch, you must specify a branch on the command line.
"너는 원격 저장소의 내용을 가져오라고 했지만 원격 저장소의 어느 브랜치인지는 말해주지 않았어. 심지어 너는 기본적으로 연결되도록 설정한 원격 브랜치도 없거든. 그니까 브랜치 지정해서 다시 요청해줘."
즉 원격 저장소의 master 브랜치의 내용을 pull 해오기를 기대했지만 못해왔다는 이야기다. 왜냐하면 내가 master 브랜치의 내용을 가져오라고 지정하지 않았기 때문이다.
이렇게 나는 원격 저장소의 master 브랜치의 내용을 반영해오지 못한 상태에서 로컬 master 브랜치에 커밋을 추가했고, 그 결과 내가 해준 "추가 작업"이 "unrelated histories "가 된 것이다.
따라서 문제 발생의 원인은 remote branch가 지정되지 않은 상태에서 git pull 명령어를 입력한 것이다. 또한 git pull, upstream, traking connection 등을 제대로 파악하지 못한채로 깃을 사용한 것도 근본적인 이유가 될 수 있겠다.
git pull
= git fetch origin + git merge [upStream branch]
만약 upStream banch를 지정해놓은 상태라면, git pull
or git pull origin
을 통해 원격 저장소의 upStream branch 내용을 가져와 로컬 브랜치에 merge 할 수 있다.
만일 upStream branch를 지정하지 않았다면 git pull을 할 때마다 로컬 브랜치에 병합할 원격 저장소의 브랜치를 명시해주면 된다.
git pull origin master
이렇게 말이다!
🤔 upStream branch 는 어떻게 지정하는데요?
(예시)
- git pull -u origin master
- git push -u origin master
와 같이 깃 명령어 + -u
옵션을 통해 내가 현재 위치한 로컬 브랜치(이것 또한 master 브랜치라고 가정하자. )가 추적할 브랜치를 설정할 수 있다.
-u는 —set-upstream의 줄임말이다.
➕ plus
💬 git fetch
원격 저장소와 로컬 저장소를 연결하여 원격 저장소의 변경사항을 가져온다. 이것이 로컬에 반영이 되지는 않는다. 단순히 가져오기만 할 뿐이다.
💬 git merge [브랜치]
현재 위치한 브랜치와 지정한 브랜치를 합친다.
💬 git rebase
두 개의 공통 Base를 가진 브랜치에서, A 브랜치의 Base를 다른 브랜치의 최신 커밋으로 설정하도록 브랜치의 Base를 옮기는 작업이다.
💬 FETCH_HEAD
원격 저장소가 병합될 때마다 생기는 최신 커밋 정보가 들어있다. 그러므로 fetch를 할 때마다 업데이트 되며, .git 폴더에서 확인해 볼 수 있다.
reference
Git pull 실행시 "no tracking information for the current branch" 오류 해결하기
[코드잇] git push -u origin master의 비밀 by 코드잇
'트러블슈팅' 카테고리의 다른 글
[Redis Error] Unable to send PING command over channel (0) | 2024.10.22 |
---|---|
springboot Could not move temporary workspace 오류 (0) | 2024.05.01 |
org.hibernate.sql 미작동 (0) | 2024.01.09 |
git push author 변경 (0) | 2023.09.04 |
400 에러 - 필드가 하나인 DTO의 기본 생성자 부재... (0) | 2023.08.22 |