Fix refusing to merge unrelated histories
Confirm why two Git histories have no common ancestor, preserve both sides, and merge only when combining independent repositories is intentional.
Git refuses the merge because the two tips have no common ancestor. This often occurs when a local repository and a remote repository were initialized separately, each with its own first commit.
Confirm that the histories are truly unrelated
git status
git fetch origin
git merge-base HEAD origin/main
git log --oneline --graph --decorate --all -20
If git merge-base produces no commit, inspect both histories. Make sure origin points to the intended repository; a wrong remote URL is safer to fix than to merge.
Prefer a clean start when one side is disposable
If the local repository has no unique work, clone the remote into a new directory. If the remote only contains a generated README and has not been shared, project owners may instead recreate it from the intended local history. Do not overwrite either side until you have identified which content matters.
Merge only when combining both projects is intentional
Create a recoverable pointer first:
git branch backup/before-unrelated-merge
git merge origin/main --allow-unrelated-histories
Resolve conflicts, especially duplicate README.md, license, and ignore files. Then run the project tests and review:
git status
git diff --check
git log --oneline --graph --decorate -20
The option bypasses one safety check; it does not decide how independent files should be combined. Abort an unfinished merge with git merge --abort if you need to reassess.
Never add --allow-unrelated-histories automatically to every pull. It is appropriate only when joining independent roots is the intended history. Read Git merge vs. rebase before choosing how future work should be integrated.