git pull --allow-unrelated-histories


1. git pull --allow-unrelated-histories 란?

--allow-unrelated-histories는 Git에서 서로 연관되지 않은 두 히스토리를 강제로 병합할 때 사용하는 옵션이다.

보통 서로 다른 프로젝트를 하나로 합치거나, 원격 저장소와 로컬 저장소가 서로 공통 조상을 갖지 않을 때 사용한다.


2. 오류 상황 예시

fatal: refusing to merge unrelated histories

🧨 언제 발생하나?


3. 해결 방법

git pull origin main --allow-unrelated-histories

4. 사용 예

# 로컬 초기화
git init
git remote add origin https://github.com/user/repo.git

# 강제 병합
git pull origin main --allow-unrelated-histories

5. 주의사항


6. 관련 옵션

옵션

설명

--rebase

병합 대신 리베이스로 히스토리 깔끔하게 유지

--no-commit

병합하되 커밋은 직접 하고 싶을 때

--strategy=ours / theirs

충돌 시 우선할 히스토리 선택





Revision #3
Created 20 May 2025 08:41:58 by Dain
Updated 28 May 2025 07:52:07 by Dain