N Kaushik

Git fatal refusing to merge unrelated histories

February 13, 2020

This error appears on git pull or git rebase mainly. Or if you are adding one new Git repository, and trying to do one pull request, it might appear. You can try any of the below methods to resolve it. If you have unpushed code, make sure to keep a backup before running any of the below commands.

—allow-unrelated-histories :

The cause of the problem is because your local git repo and remove git repo have different git histories. You can use --allow-unrelated-histories flag along with git pull to solve it :

git pull --allow-unrelated-histories

Hard reset :

If the first method doesn’t work, you can do one hard reset :

git fetch --all
git reset --hard origin/master

Make sure to take one backup before doing hard reset.

StackOverflow discussion link source

Subscribe to my Newsletter