GITHUB

[GitHub]push 충돌시 강제 해결법

먹지 2024. 3. 31. 15:35

내 프로젝트를 푸시하려고 했는데, 충돌이 나며 push가 되지 않는 상황에 처했다.

$ git push origin master
To https://github.com/laketree2/Java_Algorithm.git
 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'https://github.com/laketree2/Java_Algorithm.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

힌트대로 git pull을 여러번 시도해보았지만 해결이 되지 않았다.🤯

이럴 땐 어떻게 해야할까?


문제 상황은 로컬 마스터에서 원격으로 올라가는 과정에서 변경 사항이 있기 때문에 그 충돌을 해결해야하는 것이 되겠다. 하지만 나는 지금 최신 상황이 반영되지 않는 상황이므로, 강제로 push를 진행하는 git push --force <remote_repository>를 수행해주었다.

$ git push -f origin master

이제 원격을 확인해보면, 원하는 정보들이 제대로 올라간 것을 확인할 수 있다.


하지만 -f같은 경우는 자주 실행하지 않는 것이 좋다. 최대한 원인을 찾아서 탐색해보고, 모든 경우의 수를 시도해보았을 때 최후의 수단으로 사용하는 것을 권장한다.