The Fatal : refusing to merge unrelated histories – Git Error

Last Updated On Tuesday 7th Sep 2021

When two separate projects are merged, you may face fatal: refusing to merge unrelated histories. This occurs when projects are not aware of each other’s presence and have mismatching commit records.

fatal: refusing to merge unrelated histories

This issue has one answer that you can reuse whenever you face the problem.There might sometimes be a good reason not to do the allow.

Why Error Occurs ??

  • You may have cloned a project for which the .git directory is erased or damaged.
  • In this state, Git is unaware of your local history and will throw this error.
  • It’s because the two branches have no relationship.
  • You may have created a new repository and added commits to it.
  • Now you are trying to pull from a remote repository that already exists and already has commits.
  • Git will throw the error because it does not know how the two projects are related.

refusing to merge unrelated histories

How to Solve ??

  • You can add allow-unrelated-histories flag.
  • Managed by avoiding creating the repository with a readme. md.
  • Creating without
  • Some command already have a ‘Readme. md’ file. Modify the readme. md later on
	git pull origin master --allow-unrelated-histories
	git pull --allow-unrelated-histories

For Your Reference Documentation