DEV Community


Fatal: refusing to merge unrelated histories Git unrelated-histories and local

Muslim, Husband, Programmer, Indian/Kerala. Speaks English, Malayalam. Always curious about technology, computing etc.
・1 min read


This is a small learning about git.

  1. --allow-unrelated-histories
  2. local git copies


Unrelated histories may happen sometimes. Usually, we use git init command and create a git repo. This has some unique identity (I didn't dig into internals, I'm just speculating).

So, how the unrelated histories happen ?

Here are few scenarios, I can think.

  • One personally git init locally, and done a fair amount of coding. Another person, created git repo just for the first person.
  • If one person shares a project folder to other without initializing a git repo (ie. git init). Then, both of them git init at later stage.

Then, you might end-up in unrelated histories. Probably, you will see this error.
fatal: refusing to merge unrelated histories.

The option to fix this is

For example, see following command
git pull origin master --allow-unrelated-histories https://github/username/reponame.git

local git copies

Say two developers are working on project and both are using git. They can merge git repos locally as well.

git pull /path/to/other-copy

Actually, other operations like clone, pull, etc. work as well.


Discussion (2)

waylonwalker profile image
Waylon Walker

I've ran into this a number of times as well. I think you can run into this issue for anything that changes history, such as a rebase. I think its generally ok to git push --allow-unrelated-histories to your own repo with no collaborators, or to your own branch, steer clear with a branch that has collaborators.

ajeebkp23 profile image
Ajeeb.K.P Author

Thanks for sharing your experience and thoughts.