git pull: 'fatal: refusing to merge unrelated histories'
@devsingh05▲ 14 net votes
The local repo and the GitHub repo were each created with their own first commit (for example GitHub added a README while you ran git init locally). Run git pull origin main --allow-unrelated-histories, resolve the README or .gitignore conflict, commit, then push. To avoid it, create the GitHub repo empty, or clone it first and copy your files in.
1 COMMENT
On Git 2.33+ with no pull.rebase/pull.ff config, this pull can instead stop with 'fatal: Need to specify how to reconcile divergent branches'. Add --no-rebase (git pull --no-rebase origin main --allow-unrelated-histories) so it does one merge commit; rebasing unrelated histories replays every local commit onto the remote root and can conflict repeatedly.