fatal:refusing to merge unrelated histories git error – Fix

featured Image

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

Related Posts

git commands with example

Top 40 Git commands with Examples

GitHub has become an essential tool for developers to manage, store, and collaborate with other developers on software projects. With its simple powerful git-based version control system, GitHub allows users…

Read more
Check GitHub Account in the Terminal

Check GitHub Account in the Terminal

GitHub is an integral tool for developers to store, manage, and collaborate on software projects with other developers. And as we work more and more in the command line it…

Read more
featured Image

How to make list of objects in Netlify CMS using list and object Widget

Here in this Netlify CMS tutorial we will how easily we can make a list of objects using list and object widgets. This will allow us to add multiple objects…

Read more

Leave a Reply

Your email address will not be published. Required fields are marked *