Contents

Solution to Fatal: Refusing to Merge Unrelated Histories

Reason

When i initialize the github repository first, and push my code to it, there often occur this error:

git pull origin master                                 
fatal: refusing to merge unrelated histories

This is because git judges that two unrelated projects are merged (i.e., projects that are not aware of each other’s existence and have mismatching commit histories).

Solution

This error can be solved by toggling the allow-unrelated-histories switch. You can use this code below:

git pull origin master --allow-unrelated-histories

Reference

  1. https://www.educative.io/answers/the-fatal-refusing-to-merge-unrelated-histories-git-error
  2. https://github.com/git/git/blob/master/Documentation/RelNotes/2.9.0.txt#L58-L68