본문 바로가기

𝗚𝗜𝗧𝗛𝗨𝗕

GitHub | ERROR - error: failed to push some refs to

 

 

 

 

 

 

error: failed to push some refs to

 

github를 사용하면서 볼 때마다 머리 아픈 에러다... 

 

 

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

 

이 오류는 Git 저장소에 푸시할 때 다양한 이유로 간혹 발생할 수 있다. 보통 원격 브랜치의 변경 사항이 로컬 브랜치의 변경 사항보다 앞서 있기 때문에 발생하며, 일반적으로 git pull 명령어를 사용해 원격 브랜치의 변경사항을 가져와 로컬 브랜치에 병합하면 충돌을 해결할 수 있다. 

 

 

 

이럴 때에는 원격 저장소에서 내 로컬 저장소에

저장되지 않은 파일을 먼저 pull한 후 원격 저장소에 다시 push 해야 한다.

 

git pull

git pull origin 'main(브랜치 이름)'

 

git push

git push origin 'main(브랜치 이름)'

 

 

 

하지만 git pull -> merge -> push 순으로 해도 해결되지 않아 결국 강제 push 명령어를 사용해야 할 때가 있다. 

git push -u origin 'main(브랜치 이름)' --force

// 또는 

git push -f origin master

 

※ 만약 불가피하게 강제 push 명령어를 사용해야 하는 경우 먼저 충돌을 해결한 후 사용하는 게 좋다. 

 

 

 주의 

  • --force 옵션은 원격 저장소의 commit 이력을 변경할 수 있으므로 신중하게 사용해야 함
  • 협업(타인과 함께 저장소를 공유하고 있을 경우)을 진행하고 있을 경우
    강제 push 시 팀원의 작업에 영향을 줄 수 있음

 

 

 

'𝗚𝗜𝗧𝗛𝗨𝗕' 카테고리의 다른 글

GitHub | push한 commit 삭제하기  (0) 2024.03.13
Recent Posts
Visits
Today
Yesterday
Archives
Calendar
«   2024/10   »
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31