ShareYourGroupShareYourGroupError Explainer

Git: fatal: refusing to merge unrelated histories

A plain-words explanation of this Git message: what it means, the usual causes, and the steps that fix it.

The messagefatal: refusing to merge unrelated histories

Make the error yourself

Run with git version 2.56.0.windows.4. This is the smallest example we could find that shows it.

Setup used before these commands (a practice folder with no data)
export GIT_AUTHOR_NAME=Asha GIT_AUTHOR_EMAIL=a@example.com GIT_COMMITTER_NAME=Asha GIT_COMMITTER_EMAIL=a@example.com
git init -q -b main mine
cd mine
echo mine > a.txt
git add a.txt
git commit -qm mine
cd ..
git init -q -b main theirs
cd theirs
echo theirs > b.txt
git add b.txt
git commit -qm theirs
cd ../mine
git remote add other ../theirs
git fetch -q other
cd mine

Commands

git merge other/main

Git prints (the real message)

fatal: refusing to merge unrelated histories

Why it happens

Two branches that share no common ancestor commit have "unrelated histories". Git assumes that merging them is a mistake. It happens most often when you create a new repository on a website with a README file and a licence and also run git init and commit on your computer, so that the two sides started separately. Then your first git pull or git merge refuses.

How to fix it

  1. If you are sure that you want to combine the two projects, add --allow-unrelated-histories to the pull or merge, as in the fixed example. Fix any conflicts that appear (often the README).
  2. If the online repository is empty or unimportant, push yours with git push -u origin main after fixing the remote.
  3. To avoid it next time, create the empty repository online without a README and then push, or clone the online repository first and add your files into the clone.

The corrected version

Commands

git merge other/main --allow-unrelated-histories --no-edit

Git prints (the corrected version)

Merge made by the 'ort' strategy.
 b.txt | 1 +
 1 file changed, 1 insertion(+)
 create mode 100644 b.txt

How to avoid it

Start from one side: either clone first, or create the repository empty.

Questions

Is --allow-unrelated-histories dangerous?

It does not delete anything. It creates a merge commit that has two parents. The risk is only that you merge two things that do not belong together.

This is an independent guide. It is not connected with Python, Microsoft, Google, GitHub or the Git project. Product names belong to their owners. Examples were run on 13 November 2026 in a practice folder or a blank workbook; your version may word a message slightly differently.