Git refusing to merge unrelated histories. What is 'unrelated histories'?

When somehow the local .git subdirectory is lost, the whole project seems to be appeared from nowhere, as all the local changes histories were contained by .git. Thus, your local changes become unrelated. That is why all the changes are called unrelated histories then.

In this situation, git merge or pull request will unable to track where you made changes to add with the remote project. Hence, " refusing to merge unrelated histories"- error occurs.

In this situation, if you try to force merge by following commands,

git pull origin master --allow-unrelated-histories

git merge origin origin/master

it will create a lot of conflicts, as it is not able to find the history of your local changes.


I think you have commit in remote repository and when you pull this error happen.

use this command

git pull origin master --allow-unrelated-histories
git merge origin origin/master

I ran into a similar problem where I brought in a branch from a second remote and wanted to merge with a branch from the first remote. This is different from the existing answers as I'm not using --allow-unrelated-histories on the pull, but on the merge.

git checkout master
git merge --allow-unrelated-histories myfunnybrancy

Tags:

Git