Skip to content

/errors/git/refusing-to-merge-unrelated-histories

fatal: refusing to merge unrelated histories

verified onenvironmentlocal · windows 10.0.26200 arm64 · GNU bash 5.3.15 (Git Bash) · git version 2.55.0.windows.5updated 2026-10-20
tool
Git
exit code
128
versions
Git 2.9+
os
linux, macos, windows

Since Git 2.9, git merge and git pull stop with fatal: refusing to merge unrelated histories when the two branches have no commit in common. It usually happens when you git init a project locally and then pull from a remote that was created with its own README commit.

Reproduce the error

bash
git init -q -b main remote-project && cd remote-project
echo "# Project" > README.md && git add README.md && git commit -qm "Initial commit"
cd .. && git init -q -b main local-project && cd local-project
echo "print('hi')" > app.py && git add app.py && git commit -qm "Add app"
git pull --no-rebase ../remote-project main

Output · exit 128

From ../remote-project
 * branch            main       -> FETCH_HEAD
fatal: refusing to merge unrelated histories

With a plain git pull and no pull.rebase setting, recent Git versions (2.55 here) stop earlier with fatal: Need to specify how to reconcile divergent branches. Choose merge (--no-rebase) or rebase explicitly, as above, to reach the actual check.

Fix: allow the merge once

bash
git init -q -b main remote-project && cd remote-project
echo "# Project" > README.md && git add README.md && git commit -qm "Initial commit"
cd .. && git init -q -b main local-project && cd local-project
echo "print('hi')" > app.py && git add app.py && git commit -qm "Add app"
git pull --no-rebase --allow-unrelated-histories -q ../remote-project main
git log --oneline --graph

Output

*   4c7b4bd Merge branch 'main' of ../remote-project
|\
| * e076e41 Initial commit
* 5fc6163 Add app

The resulting merge commit joins the two root commits; later pulls work normally because the histories are now related.

Sources