Contents

10/28/2026

Git Error: refusing to merge unrelated histories

Short answer: the two histories you are joining have no commit in common, so git will not guess how to combine them. If you really mean to join two projects that began separately, add --allow-unrelated-histories to the merge or pull. If you did not mean to, you probably created a repository separately from one you wanted to share a history with, and the better fix is to start from a clone.

What it looks like

fatal: refusing to merge unrelated histories

It shows up on git merge, and on git pull, which merges after fetching. A common way to get it: you run git init and make a first commit locally, then create a repository on a hosting site with its own first commit (a README, a license) and try to pull it.

Reproduce it

We made two empty repositories with one commit each, fetched one into the other (Git 2.54.0) and merged:

git merge other/main
# fatal: refusing to merge unrelated histories

git pull other main printed the same message after its fetch.

The fix when you mean it

git merge --allow-unrelated-histories -m "merge b" other/main

That merged cleanly in our test, and git log --graph showed a merge commit with the two separate first commits as its parents. The git manual says: "By default, git merge command refuses to merge histories that do not share a common ancestor. This option can be used to override this safety when merging histories of two projects that started their lives independently" (git-merge documentation, version 2.54.0). It also calls this a very rare occasion.

Our test used two different file names. If both histories have a file at the same path with different content, expect to resolve a conflict in it; we did not test that case.

Which fix fits

  • You wanted to share history

    Clone the remote repository instead of running git init, then copy your files in and commit.

  • You are merging two real projects

    Use --allow-unrelated-histories on one merge, then check the result before you push.

  • You made a README on the remote by mistake

    Pull it with --allow-unrelated-histories, or push to an empty remote repository instead.

  • You are unsure

    Run git log --oneline on both sides. If no commit appears in both, the histories are unrelated.

Check before you merge

git log --oneline --all --graph

If your two lines of commits never meet at one commit, that is the whole explanation. Make a backup branch before merging, so a bad merge costs nothing: git branch backup-before-merge.

FAQ

What does refusing to merge unrelated histories mean?

The two branches have no common ancestor commit, so git will not combine them unless you tell it that is intended.

How do I fix refusing to merge unrelated histories?

Run the merge or pull again with --allow-unrelated-histories, if you mean to join the two histories.

Is it safe to use --allow-unrelated-histories?

It is safe when you mean to join two projects. Check the result before pushing, and back up the branch first.

Researched and drafted with AI, then reviewed and edited by the site's editors.