본문 바로가기

Git

git - forked한 local main브랜치에 잘못 푸시한 경우

728x90

현재 작성자가 속한 개발환경은 

remote 브랜치를 forked 하여 브랜치를 따로 만들어 작업한 뒤

pull request하는 환경이다. 

 

그런데 실수로 forked한 레포지토리의 

main 브랜치에다가 push를 한 경우

revert하여도 분기가 나누어져(diverged) 

pull request 할 수 없다. 

 

이런 경우 다음과 같이 해결하자

 

이런 상황


1. forked한 레포의 main 브랜치로 이동

git checkout main

 

2. upstream 의 main 브랜치 fetch 하기

git fetch upstream main

 

3. upstream main 브랜치를 내 forked한 main 브랜치로 reset 해버리기

git reset --hard upstream/main

 

4. 내 forked한 main 브랜치에 강제 푸시하기 (upstream이랑 똑같이 강제로 맞춘다.)

git push origin main --force

 

5. 차이점 확인해보기

git diff upstream main