Site icon RohuTech

“fatal: refusing to merge unrelated histories” Git Error

fatal refusing to merge unrelated histories

fatal refusing to merge unrelated histories Photo by Yancy Min on Unsplash

Have you ever came across this git error “fatal: refusing to merge unrelated histories”. If yes then this article is especially for you.

fatal: refusing to merge unrelated histories

I got this error by doing following

  1. I created a Laravel project in my local.
  2. Also, at the same time, I created a new repo on my GitHub account.
  3. Then to track the project in GitHub I simply did the following :
git initialised and added remote origin

4. and committed the changes on my local.

git local changes committed

Now, it was time to push the changes back to my remote repo. So, I simply tried to pull the changes from my remote repo, and this error occurred.

You would have understood the cause.

Yes, it was because even though I had added the remote origin on my working folder locally, my local and remote project is not related as they both were created independently and they both have no common base, which is why they both don’t know each other’s state. And therefore the error “fatal: refusing to merge unrelated histories”.

So, whenever you are in a situation like this where you local git repo is not related to your remote git repo and still you want to sync or push your changes across remote repo, you can do this

git pull origin master --allow-unrelated-histories

More on this at Git official documentation

Exit mobile version