[Git] Rebase가 필요한 순간

Jang Seok Woo·2022년 6월 30일
0

실무

목록 보기
92/136

배경 : Git을 이용하여 Refactoring하는 업무를 담당하게 되었다.
- main branch : 일반적으로 작업하는 결과를 모아두는 branch
- refactor-products-list branch : 내가 작업을 위해 새로 판 branch

먼저 git repo의 main에 있는 코드를 clone하였고,

main 브랜치에서 새 브랜치를 생성하여 refactor-products-list 브랜치를 만들었다.


이틀간 작업을 한 후,


작업 브랜치인 main브랜치는 중간에 업데이트가 있었고, 나는 깡깡이라 몰랐다.

작업 변경사항을 push 하기 전에, 로컬 main으로 체크아웃하여 업데이트된 main을 pull 받아 코드를 최신화하였다.

이후 로컬 refactor-products-list 브랜치로 merge하고, 체크아웃하고 난뒤 commit 하였다.

git push origin refactor-products-list

이걸로 작업사항을 remote에 올리면 되는데, 안올라간다.

오류 메시지는

"Updates were rejected because the tip of your current branch is behind its remote counterpart..."

리모트랑 로컬이랑 다르니까 pull해서 최신화 하라는 것 같은데.. 나 했는데?
그래서 다시

git pull origin refactor-products-list

오류난다

"You have divergent branches and need to specify how to reconcile them..."

생각해보니 여기가 아닌가.. 하고 main으로 체크아웃해서

git pull origin main

오류난다

"You have divergent branches and need to specify how to reconcile them..."

이럴 경우, rebase를 이용하여 manually solving the conflicts해야한다는 문구가 나온다.


해결 방법

작업 브랜치를 기준으로 --rebase를 한다.

git pull origin refactor-product-list --rebase

갑자기 브랜치가 23534634 이런 종류의 이름으로 바뀌어있을 것이다.

여기서 수작업으로 충돌 부분을 해결하며 지정해주면 된다.

그 이후,

git rebase --continue

하고,

새로 pull push를 진행하면 이상없이 잘 된다.

During 'push Trial', met "Updates were rejected because the tip of your current branch is behind its remote counterpart." message.
also During 'pull Trial', met "You have divergent branches and need to specify how to reconcile them." message.

Understanding the situation, I do 'rebase' to resolve the conflicts manually.

profile
https://github.com/jsw4215

0개의 댓글