본문 바로가기
DevOps/Git

[해결 방법] fatal: refusing to merge unrelated histories

by HJ0216 2023. 1. 22.

발생 Error

Git Bash에서 다음 명령어를 입력할 경우,

$ git pull origin main
remote: Enumerating objects: 247, done.
remote: Counting objects: 100% (247/247), done.
remote: Compressing objects: 100% (187/187), done.
remote: Total 247 (delta 73), reused 157 (delta 38), pack-reused 0
Receiving objects: 100% (247/247), 59.49 KiB | 378.00 KiB/s, done.
Resolving deltas: 100% (73/73), done.
From https://github.com/HJ0216/TIL
 * branch            main       -> FETCH_HEAD
 * [new branch]      main       -> origin/main

fatal: refusing to merge unrelated histories

fatal: refusing to merge unrelated histories

Error 발생

 

 

Error 원인

pull 명령어는 fetch와 merge를 한 번에 처리하는 명령어인데, merge가 되지 않는 상황

(fetch: 원격 저장소 내용 가져오기, merge: 로컬 저장소의 내용과 원격 저장소의 내용 병합하기)

 

push 명령은 로컬 저장소의 commit log와 원격 저장소의 commit log를 보고, 원격 저장소의 마지막 commit id와 동일한 commit id를 가진 로컬 저장소의 commit 시점을 찾아낸 뒤, 원격 저장소의 마지막 commit과 연결

 

commit histories가 서로 관련이 없을 경우, 즉 공통된 commit 지점이 존재하지 않을 경우, merge할 수 없음

 

 

해결 방법

1. git clone 명령어를 통해 원격 저장소 복제

2. pull 명령어 + 옵션을 통해 merge 진행

$ git pull origin main --allow-unrelated-histories
From https://github.com/HJ0216/TIL
 * branch            main       -> FETCH_HEAD
Merge made by the 'ort' strategy.
 AI/ann_model.py                   |  65 +++++++++++++++++
 AI/dacon_seoul_ddarung.py         | 103 ++++++++++++++++++++++++++
 AI/data_shape.py                  |  90 +++++++++++++++++++++++
 AI/evaluate_and_predict.py        |  51 +++++++++++++
 AI/hyperParameter_Tuning.py       |  40 ++++++++++
 AI/indicator_with_california.py   |  61 ++++++++++++++++
 AI/mae_and_mse.py                 |  48 ++++++++++++
 AI/matplotlib_plot2.py            |  44 +++++++++++
 AI/matplotlib_scatter_and_plot.py |  81 +++++++++++++++++++++
 AI/missing_value_handling.py      | 149 ++++++++++++++++++++++++++++++++++++++
 AI/multiLayer_Perceptron.py       |  74 +++++++++++++++++++
 AI/r2_score.py                    |  64 ++++++++++++++++
 AI/rmse_def.py                    |  63 ++++++++++++++++
 AI/split_train_test1.py           |  51 +++++++++++++
 AI/split_train_test2.py           |  58 +++++++++++++++
 AI/split_train_test3.py           |  68 +++++++++++++++++
 AI/useful_method_from_numpy.py    |  18 +++++
 README.md                         |  68 +++++++++++++++++
 18 files changed, 1196 insertions(+)
 create mode 100644 AI/ann_model.py
 create mode 100644 AI/dacon_seoul_ddarung.py
 create mode 100644 AI/data_shape.py
 create mode 100644 AI/evaluate_and_predict.py
 create mode 100644 AI/hyperParameter_Tuning.py
 create mode 100644 AI/indicator_with_california.py
 create mode 100644 AI/mae_and_mse.py
 create mode 100644 AI/matplotlib_plot2.py
 create mode 100644 AI/matplotlib_scatter_and_plot.py
 create mode 100644 AI/missing_value_handling.py
 create mode 100644 AI/multiLayer_Perceptron.py
 create mode 100644 AI/r2_score.py
 create mode 100644 AI/rmse_def.py
 create mode 100644 AI/split_train_test1.py
 create mode 100644 AI/split_train_test2.py
 create mode 100644 AI/split_train_test3.py
 create mode 100644 AI/useful_method_from_numpy.py
 create mode 100644 README.md

➕ git pull 명령어

origin: remote repository의 URL short name

main: main branch의 remote repository

 

 

이후, push 재 진행

$ git push -u origin main
Enumerating objects: 6, done.
Counting objects: 100% (6/6), done.
Delta compression using up to 8 threads
Compressing objects: 100% (4/4), done.
Writing objects: 100% (4/4), 520 bytes | 520.00 KiB/s, done.
Total 4 (delta 1), reused 0 (delta 0), pack-reused 0
remote: Resolving deltas: 100% (1/1), done.
To https://github.com/HJ0216/TIL.git
   5376d70..1843ac3  main -> main
branch 'main' set up to track 'origin/main'.

 

필요없는 Branch 제거

$ git push origin --delete master
To https://github.com/HJ0216/TIL.git
 - [deleted]         master

 

 

 

참고 자료

📑 fetch, 원격 저장소의 데이터를 로컬에 가져오기만 하기

📑 git push, pull (fatal: refusing to merge unrelated histories) 에러

📑 git branch 삭제

📑 git pull, push와 origin의 의미