Sometimes you get the following error while trying to pull updates from remote repoistory:

fatal: refusing to merge unrelated histories

Two possibilities when this can happen:

  1. You have cloned a project and, somehow, the .git directory got deleted or corrupted. This leads Git to be unaware of your local history and will, therefore, cause it to throw this error when you try to push to or pull from the remote repository.

  2. You have created a new repository, added a few commits to it, and now you are trying to pull from a remote repository that already has some commits of its own. Git will also throw the error in this case, since it has no idea how the two projects are related.

Solution

Add the --allow-unrelated-histories flag to enforce pulling, For Example:

git pull origin master --allow-unrelated-histories

git series1 - Generate SSH key2 - Fixing fatal: refusing to merge unrelated histories3 - Get ssh key4 - Delete Branch Locally5 - Delete Branch From Remote Repository6 - How to Undo a Git Add7 - Merge Two Branches Locally
git#git