Computer >> Computer tutorials >  >> Programming >> Programming

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

The 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. 

This .git directory is the way a version control tracks your changes from the remote repository. You can see this directory exists when you input the ls -a command in the root directory of your local repository. The list that results has the .git directory there.

Git refusing to merge unrelated histories

Because the .git 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.

The Solution

Git’s solution for this to pull the remote repo into your project with the escape hatch --allow-unrelated-histories.

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.

81% of participants stated they felt more confident about their tech job prospects after attending a bootcamp. Get matched to a bootcamp today.

The average bootcamp grad spent less than six months in career transition, from starting a bootcamp to finding their first job.