fatal: refusing to merge unrelated histories
Git’s fatal: refusing to merge unrelated histories error happens when you try to merge two branches (or repos) that have no common ancestor commit, and Git blocks the merge to prevent an accidental integration of completely separate projects.
What It Means
Git tracks history as a chain of commits. When you merge branch A into branch B, Git expects them to share at least one common commit — their last common ancestor. If they don’t share any commit history, Git refuses to merge because it can’t determine how to reconcile the two divergent histories.
Why It Happens
- You created a new repo with
git init, made commits, then tried togit pullfrom an existing remote repo — your local history and the remote history share no common commits. - You’re merging two branches that were created independently and never shared a base.
- You used
git checkout --orphanto create an orphan branch with no parent, then tried to merge it. - You’re combining two separate repositories that were never linked.
How to Fix It
1. Allow unrelated histories during merge
Pass the --allow-unrelated-histories flag to override Git’s safety check:
git merge --allow-unrelated-histories <branch-name>Or during a pull:
git pull origin main --allow-unrelated-histories2. Handle merge conflicts
Since the two histories have no common base, every file difference will appear as a conflict. Resolve them manually or accept all incoming/current changes:
# Accept all incoming changes
git merge --allow-unrelated-histories <branch-name> -X theirs
# Or accept all current branch changes
git merge --allow-unrelated-histories <branch-name> -X ours3. Rebase instead of merge (alternative)
If you want a linear history, fetch and rebase with the same flag:
git fetch origin
git rebase --allow-unrelated-histories origin/main4. Verify the result
git log --oneline --graph --allThis shows the combined commit graph.
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro