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.
.gitfolder 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.
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.