/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
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 mainOutput · 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
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 --graphOutput
* 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
Related pages
errors · giterror: failed to push some refs (rejected, fetch first)git push is rejected with failed to push some refs when the remote branch has commits you do not have. Pull or fetch and rebase first, then push again safely.errors · gitfatal: not a git repository (or any of the parent directories): .gitGit prints not a git repository when the current folder and none of its parents contain a .git directory. cd into the repository, run git init, or set GIT_DIR.compare · gitgit merge vs git rebase: differences and when to use eachgit merge joins histories with a merge commit and keeps them as they happened; git rebase replays commits on a new base for a linear history with new hashes.