Fix Git "fatal: refusing to merge unrelated histories"
Git blocks merging two branches that do not share a common commit ancestor (common when initializing a local git repository and pulling from a GitHub repository initialized with a README).
fatal: refusing to merge unrelated histories
Quick Fix Checklist
- Run git pull with the override flag: git pull origin main --allow-unrelated-histories
- Resolve any merge conflicts in your editor (e.g. conflicting README.md or .gitignore)
- Stage and commit: git add . && git commit -m "Merge remote and local histories"
- Push your merged branch: git push -u origin main