Skip to main content
Git & Version Control · Developer Error Resolution Lab

Fix Git Error: 'fatal: refusing to merge unrelated histories'

Merge repositories initialized independently with different initial commits using --allow-unrelated-histories.

Triggered Error Message:

fatal: refusing to merge unrelated histories

Customize Solution for Your Environment
# Run pull with unrelated histories enabled:
git pull origin main --allow-unrelated-histories

# Resolve any merge conflicts, then commit:
git add .
git commit -m "Merge unrelated remote history"
git push origin main

Root Cause & Mechanism Analysis

Why does this error occur?

Occurs when pulling from a remote repository that was initialized independently (e.g. with a README generated on GitHub) while having existing local commits.

Frequently Asked Questions

Is it safe to run --allow-unrelated-histories?
Yes, provided you review any conflicting files (like README.md or .gitignore) before finalizing the merge commit.
Browse All 35 Guides