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
- Run: git pull origin main --allow-unrelated-histories
- Resolve any conflicting files (such as duplicate README.md or .gitignore)
- Stage resolved files: git add .
- Finalize the merge commit: git commit -m "Merge remote and local histories"
- Push your changes safely: git push -u origin main