Git Diagnostic

How to Fix "fatal: refusing to merge unrelated histories" in Git

Git blocks pull or merge operations when two repositories or branches do not share a common root commit history, typically when creating a new local repo and linking to a pre-initialized GitHub repository.

fatal: refusing to merge unrelated histories

Quick Fix Checklist

  1. Run: git pull origin main --allow-unrelated-histories
  2. Resolve any conflicting files (such as duplicate README.md or .gitignore)
  3. Stage resolved files: git add .
  4. Finalize the merge commit: git commit -m "Merge remote and local histories"
  5. Push your changes safely: git push -u origin main