Git fatal: refusing to merge unrelated histories - Rocketeers app

  [ Rocketeers ](/)   

[Login](https://rocketeersapp.com/login) 

 On this page

 Knowledge
---------

Git fatal: refusing to merge unrelated histories
================================================

### [\#Git](https://rocketeersapp.com/knowledge/git)

This error means Git found no common ancestor between the two branches you are merging. It is a safety check, and there is a one-flag override once you are sure the merge is intentional.

 Published by [Mark van Eijk](https://rocketeersapp.com/author/mark-van-eijk) on June 23, 2026 · 1 minute read

1. [About the error](#content-about-the-error)
2. [Why do I see this error](#content-why-do-i-see-this-error)
3. [Solution](#content-solution)
4. [Before you use the flag](#content-before-you-use-the-flag)

[\#](#content-about-the-error "Permalink")About the error
---------------------------------------------------------

 ```
fatal: refusing to merge unrelated histories

```

Introduced in Git 2.9, this is a guard rail. When you merge or pull, Git looks for a shared commit the two histories descend from. If there isn't one, it refuses rather than stitch together two genuinely separate project histories by accident.

[\#](#content-why-do-i-see-this-error "Permalink")Why do I see this error
-------------------------------------------------------------------------

- You created a repository locally (with its own commits) and then tried to pull from a remote that was also initialised separately, two roots, no shared ancestor.
- You're merging a branch that was started from scratch rather than branched off the others.
- The `.git` directory was deleted and recreated, so Git lost the shared history it used to know about.

[\#](#content-solution "Permalink")Solution
-------------------------------------------

If you've confirmed the merge really is intended (you genuinely want to combine these two histories), pass the override flag:

 ```
git pull origin main --allow-unrelated-histories

```

Or, if you're merging a local branch:

 ```
git merge other-branch --allow-unrelated-histories

```

Git will create a merge commit joining the two roots, and from then on they share history, so you only need the flag once.

### [\#](#content-before-you-use-the-flag "Permalink")Before you use the flag

The error is often a sign something is off, so it's worth a sanity check first:

- Are you pushing to the **right remote**? A typo'd remote URL pointing at an unrelated repo triggers this.
- Did you mean to **clone** instead of init + pull? If the remote already has the project, cloning it fresh avoids the whole situation.

 ```
git remote -v   # confirm the remote points where you expect

```

If the remote is wrong, fix it rather than forcing the merge:

 ```
git remote set-url origin git@github.com:you/correct-repo.git

```

For the related "your push was rejected" situation, see [Git updates were rejected (non-fast-forward)](/git-updates-were-rejected-non-fast-forward).

### Subscribe to our newsletter

Do you want to receive regular updates with fresh and exclusive content to learn more about web development, hosting, security and performance? Subscribe now!

  Fill in your email address to receive updates  Subscribe 

#### More in [\#Git](https://rocketeersapp.com/knowledge/git)

- [Removing tracked files in Git that should have been ignored](https://rocketeersapp.com/knowledge/removing-tracked-files-git)
- [Change casing of file or directory in Git](https://rocketeersapp.com/knowledge/change-casing-of-file-or-directory-in-git)
- [GitHub Permission denied (publickey)](https://rocketeersapp.com/knowledge/github-permission-denied-publickey)
- [Git fatal: not a git repository](https://rocketeersapp.com/knowledge/git-not-a-git-repository)
- [Git: Updates were rejected (non-fast-forward)](https://rocketeersapp.com/knowledge/git-updates-were-rejected-non-fast-forward)
