fatal:refusing to merge unrelated histories git error – Fix

This article is about how to resolve “fatal:refusing to merge unrelated histories” in git error.

This error occurs when we try to merge two completely unrelated git repositories together into one.

Before git 2.9, git merge allowed the merge of two different repositories with unrelated histories, but its used to cause lots of errors when done by mistake.

However with the update of git 2.9, it is not allowed by default, now we have to add a flag to specify the unrelated merge.

Cause of the merge error

  1. When you have a local repository and you try to push your changes on a newly created repository in GitHub.
  2. When your .git folder is corrupted or deleted by mistake. And this makes the local change histories unrelated. And we get the error when we try to pull or merge our changes to and from a remote repository.

Fix for fatal: unrelated histories error in git

To resolve the refusing to merge error, we have to allow the merge of the unrelated repository manually with the following tag --allow-unrelated-histories after the git pull or git merge command.

git pull origin master --allow-unrelated-histories

or for merge,

git merge --allow-unrelated-histories mybranchname

NOTE : make sure you do not use –allow-unrelated-histories flag unless you are sure about it. This check is use to prevent disaster when we merge unrelated repository.


Related Topics:

Open Github Repository Directly In Vscode In Browser Online

How To Create New Folder In Github?

Your Git Gateway backend is not returning valid settings – Fix

How to remove node_modules from github or bitbucket

GitHub “fatal: remote origin already exists” error – Fix

Scroll to Top