When two unrelated projects are merged, you may encounter the fatal: refusing to merge unrelated histories
Git error. This happens when projects are not aware of each other’s existence and have mismatching commit histories.
We may consider two cases that throw this :
You may have cloned a project for which the
.git
directory is deleted or corrupted. In this situation, Git is unaware of your local history and will throw this error when trying to push to or pull from the remote repository.You may have created a new repository and added commits to it. Now you are trying to pull from a remote repository that already exists and already has commits. Git will throw the error in this case, because it does not know how the two projects are related.
"Refusing to merge unrelated histories" solution
You can solve this issue by adding the allow-unrelated-histories
flag. After executing git pull
or git merge
, add the following flag:
git pull origin master --allow-unrelated-histories
Git provides more information regarding this :
https://github.com/git/git/blob/master/Documentation/RelNotes/2.9.0.txt#L58-L68
Cover Image : Markus Spiske (@markusspiske) from Unsplash
Top comments (1)
I am facing this same issue. I have 3 branches, dev, release and master. I have a git action the merges release to master after I merge dev to release and I keep getting this error. Are there any future consequences to using this?