git
merge
ai_generated
true
fatal: refusing to merge unrelated histories
ID: git/refusing-to-merge-unrelated
96%Fix Rate
97%Confidence
50Evidence
2023-01-01First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 2 | active | — | — | — |
| 2 | active | — | — | — |
| 2 | active | — | — | — |
Root Cause
Two branches have no common ancestor, typically when merging a repo that was initialized independently.
genericWorkarounds
-
95% success Use --allow-unrelated-histories flag: git merge main --allow-unrelated-histories
Explicitly allows merging branches with no common ancestor
Sources: https://git-scm.com/docs/git-merge#Documentation/git-merge.txt---allow-unrelated-histories
-
80% success Use git rebase --onto to graft one history onto the other
More complex but produces a linear history
Dead Ends
Common approaches that don't work:
-
Force-pushing one branch over the other
90% fail
Destroys one side's entire history
-
Creating a new repo and copying files
85% fail
Loses all git history from both repos
Error Chain
Frequently confused with: