git merge ai_generated true

fatal: refusing to merge unrelated histories

ID: git/refusing-to-merge-unrelated

Also available as: JSON · Markdown
96%Fix Rate
97%Confidence
50Evidence
2023-01-01First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
2 active
2 active
2 active

Root Cause

Two branches have no common ancestor, typically when merging a repo that was initialized independently.

generic

Workarounds

  1. 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

  2. 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:

  1. Force-pushing one branch over the other 90% fail

    Destroys one side's entire history

  2. Creating a new repo and copying files 85% fail

    Loses all git history from both repos

Error Chain

Frequently confused with: