git-fatal-refusing-to-merge-unrelated-histories

git pullfatal: refusing to merge unrelated histories

상황

가 PC에서
새로운 저장소(repositories)를 clone하고,
index.html 을 아래와 같이 생성하여 add, commit, push를 했다.

1
Hello, world
1
2
3
git add index.html
git commit -m "Added index.html"
git push

나 PC에서도 새로운 저장소를 clone하고,
폴더를 만들고 예제 파일들을 만들고 있었다.
내가 가 PC에서 푸시했다고 나 PCSJ님에게 알려줬다.
나 PCSJ님은 git pull을 시도했고,
아래와 같이 fatal: refusing to merge unrelated histories라는 문장을 보게 되었고,
git pull이 완료되지 않았다.

1
2
git pull
fatal: refusing to merge unrelated histories

왜 안되는거야?

공식적인 이유는 다음과 같다고 한다.

“git merge” used to allow merging two branches that have no common base by default, which led to a brand new history of an existing project created and then get pulled by an unsuspecting maintainer, which allowed an unnecessary parallel history merged into the existing project. The command has been taught not to allow this by default, with an escape hatch “–allow-unrelated-histories” option to be used in a rare event that merges histories of two projects that started their lives independently

“git merge”는 기본적으로 공통 기반이없는 두 개의 분기를 병합하여 기존 프로젝트의 새로운 히스토리를 작성한 후 예상치 못한 관리자가 가져온 것으로, 불필요한 병행 이력이 기존 프로젝트에 병합되도록 허용하는 데 사용되었습니다 . 이 명령은 기본적으로 허용하지 않도록 배웠습니다. 독립된 삶을 시작한 두 프로젝트의 기록을 병합하는 드문 이벤트에서 탈출 해치 --allow-unrelated-histories 옵션을 사용할 수 있습니다.

이렇게 하자

아래와 같이 하면 git pull이 잘 수행된다.

1
git pull origin <branch> --allow-unrelated-histories