fatal: refusing to merge unrelated histories git

The issue:

We ran into this issue when we tried to pull a remote branch to a local branch. Basically both the repositories had different histories. As soon as you tried to pull the remote repository we got the following error:

fatal: refusing to merge unrelated histories

This was not an issue before git version 2.9. The default behaviour has changed since Git 2.9:

The reason:

"git merge" used to allow merging two branches that have no common base by default, which led to a brand new history of an existing project created and then get pulled by an unsuspecting maintainer, which allowed an unnecessary parallel history merged into the existing project. 

This is no longer supported by default. --allow-unrelated-histories option needs to be added to run the command.

The solution

We need to run the following command to solve the issue:

git pull origin <branchname> --allow-unrelated-histories