본문 바로가기
Git

error: failed to push some refs to 에러 해결

by sliora 2022. 6. 23.

 

 

 

문제

To 깃주소/레포지토리.git ! [rejected] main -> main (fetch first)

error: failed to push some refs to '깃주소/레포지토리.git'

hint: Updates were rejected because the remote contains work that you do

hint: not have locally. This is usually caused by another repository pushing

hint: to the same ref. You may want to first integrate the remote changes hint: (e.g., 'git pull ...') before pushing again.

 

해결

에러가 뜨는 이유를 먼저 알아야 하는데, Github나 Gitlab에서 먼저 생성된 Repository에 처음 Push를 하려고 할 때 ReadMe.md 파일과 충돌이 생겨서 발생하는 에러이다.

 

명령어

git pull --rebase origin main 

 

위 명령어를 사용하여 pull해주고 다시 push를 해주면 된다.

일부 블로그에서는 --force를 사용하는데 --force 명령어는 비추천 함