[Git] git push error - (fatal: refusing to merge unrelated histories) 해결법

오도원공육사·2021년 10월 26일
0

git

목록 보기
4/5

로컬 저장소에 있는 프로젝트를 원격 저장소로 push할 경우에 이런 에러가 발생할 수 있다. 특히 원격 저장소를 먼저 만들고나서 git clone이 아닌 git remote add origin으로 연결해서 push할 때 이런 에러가 자주 발생한다.

C:\Users\PycharmProject>git push origin main
To https://github.com/ohdowon064/project.git
 ! [rejected]        main -> main (non-fast-forward)
error: failed to push some refs to 'https://github.com/ohdowon064/project.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을 해서 원격 저장소의 프로젝트를 병합한 뒤에 git push해야 한다.

git pull origin [브랜치명] --allow-unrelated-histories

--allow-unrelated-histories옵션은 이미 존재하는 로컬/원격 프로젝트의 기록을 저장하는데 사용된다. git에서는 일반적으로 서로 관련없는 두 프로젝트를 병합하는 것을 제한한다. 즉, 현재 원격 저장소와 로컬 저장소의 프로젝트를 관련없는 프로젝트라고 판단하여 git pull을 거부한 것이다. 그래서 해당 옵션을 사용하여 허용해준 것이다.

profile
잘 먹고 잘살기

0개의 댓글