Resolve- Refusing to merge unrelated histories git error


This article is about how to resolve refusing to merge unrelated histories error in git

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

Before git 2.9, git merge allowed the merge of two different repository with unrelated histories, but it use to cause lots of error 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 specific the unrelated merge.

Cause of the merge error

  1. When you have a local repository and you try to push you changes on a newly created repository in GitHub.
  2. When your .git folder is corrupted or deleted by mistake. And this makes the local changes 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:

How To Force Git Pull To Overwrite Local Files ?

Open Github Repository Directly In Vscode In Browser Online

How To Create New Folder In Github?


💾 Recommended Articles