Git refusing to merge unrelated histories
There are several places in the git workflow that can cause errors. In this article, we’ll talk about one such error that is confusing to tackle and find a solution to!
The Git Error
fatal: refusing to merge unrelated histories
error occurs when you have cloned a project from a git repository and somewhere along the line, that special .git directory is deleted or gets corrupted.
directory is the way a version control tracks your changes from the remote repository. You can see this directory exists when you input the
command in the root directory of your local repository. The list that results has the
Find Your Bootcamp Match
- Career Karma matches you with top tech bootcamps
- Access exclusive scholarships and prep courses
directory is damaged or deleted, the version control is unaware of your local history and will throw this merge unrelated histories error when you push or pull from the remote repo.
Git’s solution for this to pull the remote repo into your project with the escape hatch
git pull origin master --allow-unrelated-histories
This allows the two projects to merge with non-matching git history. More information can be found here on
Git’s official documentation
If you try to push after entering the pull command, you should now be able to do it.