Member-only story
How to fix “fatal: refusing to merge unrelated histories” in git
Recently, I had to create a new GitHub repository to host GitHub App token generator Actions, but I had to delete it and to recreate a new one because there was a process to create a new repository.
I deleted the repository from GitHub, created a new one, then I relinked the new repository with git remote add orgin command.
But then when I tried to pull new updates from GitHub repository, I was getting this nasty error “fatal: refusing to merge unrelated histories”.
And this was after I encountered a previous issue with git pull command. This error occurred because the merge becomes incompatible due to two histories (one in new GitHub repository and one that I cloned) are different.
The easiest way to solve is by passing--allow-unrelated-histories option in git pull.
git pull origin main — allow-unrelated-histories
However, if you want an alternative route, you can stash with git stash command, git pull, then pop with git pop, and resolve the conflict.