Skip to content

Instantly share code, notes, and snippets.

@ravivamsi
Last active June 24, 2019 17:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ravivamsi/5d228f9aaad1900fe63cff092a73e6fe to your computer and use it in GitHub Desktop.
Save ravivamsi/5d228f9aaad1900fe63cff092a73e6fe to your computer and use it in GitHub Desktop.
git pull - fatal: refusing to merge unrelated histories

GIT Unrelated Histories

When you try to pull a remote branch to a local with two unrelated histories or merge two branches with unrelated hisotories, you will encounter this error.

$ git pull
fatal: refusing to merge unrelated histories

Resolution

This issue can be resolved in 2 ways:

Accept both branch histories

We can accept and have both branch histories by using the argument --allow-unrelated-histories Note: If you habe the same file name with changes, it will result in conflicts and these are supposed to be resolved manually

Pull changes from Remote Branch

$ git pull --allow-unrelated-histories
Merge made by the 'recursive' strategy.

Merge changes from branchB and merge to branchA

$ git checkout branchA
$ git merge branchB --allow-unrelated-histories
Merge made by the 'recursive' strategy.

Accept current branch history alone

Push changes from local branch to remote

Note: This will override the changes present in the remote.

$ git push --force

Merge from branchB and merge to branchA (Keep branchA history)

$ git checkout branchA
$ git merge branchB -X ours || die "complex merge conflict"

Merge from branchB and merge to branchA (Keep branchB history)

$ git checkout branchA
$ git merge branchB -X theirs || die "complex merge conflict"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment