본문 바로가기
Git

[Git] fatal: refusing to merge unrelated histories

by 개발도사(진) 2024. 1. 17.

remote repository를 변경할 일이 있어서 git bash에 다음 command를 입력하여 remote repository를 변경하였다.

git remote set-url origin [new repository]

 

새로운 repository에 .gitignore 등의 파일이 생겼고, local에서 push하기 전에 pull을 시도했더니 해당 오류가 발생했다.

 

서로 연결된 적이 없는 두 프로젝트를 merge하려고 하면 git에서 이를 거부하는 것이라고 한다. 때문에 이를 강제로 진행 가능하도록 허가해 주어야 한다. 

git pull origin main --allow-unrelated-histories

 

--allow-unrelated-histories를 붙여서 pull을 시도하면 해당 오류 없이 pull이 가능하고, 이후 기존에 push 하려던 commit을 push해 주면 된다. 

'Git' 카테고리의 다른 글

[Git] 특정 브랜치만 clone해 오기  (0) 2023.01.16
[Git] 원격 저장소 확인, 삭제, 변경  (0) 2023.01.15
[Git] git status 분석 기초  (1) 2023.01.03
[Git] git log 읽기 & git diff  (0) 2023.01.02
[Git] Stage & Commit  (1) 2023.01.02