Git Push 에러 ([Rejected] main -> main (Fetch First) Error: Failed To Push Some Refs To)
Git

Git Push 에러 ([Rejected] main -> main (Fetch First) Error: Failed To Push Some Refs To)

728x90
반응형

ERROR

! [rejected] main -> main (fetch first)
error: failed to push some refs to 'https://github.com/~~'
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.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

 

원인: 깃의 원격저장소와 현재 로컬저장소가 동기화되어 있지 않기때문에 나타나는 문제이다. 

해결: 동기화 시켜주면됨. (git pull --rebase [원격저장소별칭] [브랜치])

 

git pull --rebase origin main

 

다시 push 해보면 잘 된다.

 


(2021.06.03 수정)

rebase를 생각하기 전에 README 파일 때문이 아닌가 생각해보자. README 파일을 처음에 pull하지 않아 문제가 발생하였다. 중간에 다시 pull하는 것도 소용이 없었는데 해결방법은 아래와 같다.

 

git pull origin main --allow-unrelated-histories

 

P.S

Github에 새로운 원격저장소를 만들고 로컬 저장소와 연동할때 git pull origin main을 잊지 말자.

728x90
반응형

'Git' 카테고리의 다른 글

뒤늦은 .gitignore 적용하기  (0) 2021.04.26
Git 에 대한 정리  (0) 2021.04.26
warning: LF will be replaced by CRLF  (0) 2021.04.25