Fatal: refusing to merge unrelated histories

You have received the dreaded fatal: refusing to merge unrelated histories error!

Why does this happen?

Git is all about Deltas (the difference between 2 or more states of something), and if you have 2 histories that don’t appear to have the same bunch of things, then it won’t know what to change, or in what order.

At this point, a fatal error will be thrown stating refusing to merge unrelated histories.

It actually makes perfect sense. But how do we fix it?

How to fix merging unrelated histories

Option 1 (easy)

The easiest way is to git clone the remote repo into a new directory (~/tmp) or somewhere like that (a throwaway) and then simply copy/paste all your files that you want in there and then git push them.

Option 2 (better)

Use the --allow-unrelated-histories flag to just force it through!

Note that this could work if you know what you’re doing, but could well break everything, so use it at your own risk!

git pull origin branchname --allow-unrelated-histories

The commands to use

git pull origin master --allow-unrelated-histories
git merge origin origin/master
... add and commit here...
git push origin master

Tags:
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments