Skip to main content

Explore your training options in 10 minutes

Git refusing to merge unrelated histories

Christina Kopecky - December 29, 2020

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.

Get offers and scholarships from top coding schools illustration

Find Your Bootcamp Match

  • Career Karma matches you with top tech bootcamps
  • Access exclusive scholarships and prep courses

By continuing you agree to our Terms of Service and Privacy Policy , and you consent to receive offers and opportunities from Career Karma by telephone, text message, and email.

Directory contents after ls -a
When you use the ls -a command, it will list all files in your directory, including those beginning with ‘.’.

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.

About us: Career Karma is a platform designed to help job seekers find, research, and connect with job training programs to advance their careers. Learn about the CK publication.

What's Next?

Christina Kopecky

About the author: Christina is an experienced technical writer, covering topics as diverse as Java, SQL, Python, and web development. She earned her Master of Music in flute performance from the University of Kansas and a bachelor's degree in music with minors in French and mass communication from Southeast Missouri State. Prior to joining the Career Karma team in June 2020, Christina was a teaching assistant, team lead, and section lead at Lambda School, where she led student groups, performed code and project reviews, and debugged problems for students. Christina's technical content is featured frequently in publications like Codecademy,, and Educative.

Skip to main content