Git: How to merge two histories with no common base
NicolasBrondinBernard
Fix the "refusing to merge unrelated histories" Git error with a simple parameter in your `git merge` command!

Article published on 27/05/2024, last updated on 10/08/2026
If you have already encountered this kind of error message with Git:
fatal: refusing to merge unrelated histories
This probably means that something wasn't done correctly… But that's okay!
The problem
This error often happens (but not exclusively) at the beginning of a project.
For example, you retrieve an empty project from GitHub/GitLab/… and you start working directly on a dev branch.
At the same time, you add a file (README.md for example) on the main branch.
But when it comes time to do a git merge, Git will refuse to do anything, because the base of the two histories is completely different.
Fortunately, the solution is very simple
The solution
To force Git to merge the two histories, you just need to rerun your git merge command with the following option: --allow-unrelated-histories
In the case where certain files exist in both branches with different contents, then you will need to resolve the conflict.
But once that's done, your merge will be perfectly functional!
Good to know
Previously, git merge agreed to merge two histories even when they were different, but this feature has changed since version 2.9
See the changelog
The git pull command, on the other hand, automatically passes the --allow-unrelated-histories option by default, which avoids this kind of problem, especially at the beginning of the project.
Complete courses, exercises and certificates to really learn programming!
4.8 average rating
No comments yet