git · Git
The message
fatal: refusing to merge unrelated histories
What it means
The two sides you are merging share no common ancestor at all, so as far as git is concerned they are two unrelated projects. It usually appears when you started locally with git init, made a few commits, then added a remote that already had commits of its own and pulled. --allow-unrelated-histories does merge them, but it welds two unrelated histories together at a single commit and that is hard to unpick later; with only a few local commits it is cleaner to clone the remote fresh and copy your files into it.
The fix
git pull origin main --allow-unrelated-histories- Printed by
- git
- Git
- 29
Almost every git error is a refusal that means "doing that from this state would lose something"; fatal: means git stopped without changing anything, and the hint: lines under the first line usually carry the actual remedy.
Reading an error message
- Read from the first line down. The lower you go the more it is about the tool’s internals; the cause is usually at the top.
- If there is a file and a line number, start there — not the top stack frame, but the topmost line that names a file you wrote.
- Search the message verbatim, but strip your own paths and variable names first; those are what stop the search from matching.
- The same condition is worded differently across tool versions. If results look wrong, add the version number to the query.
- Before pasting a fix, check what it throws away. Some of these cannot be undone.
Common questions
Q. What does “fatal: refusing to merge unrelated histories” mean?
The two sides you are merging share no common ancestor at all, so as far as git is concerned they are two unrelated projects. It usually appears when you started locally with git init, made a few commits, then added a remote that already had commits of its own and pulled. --allow-unrelated-histories does merge them, but it welds two unrelated histories together at a single commit and that is hard to unpick later; with only a few local commits it is cleaner to clone the remote fresh and copy your files into it.
Q. How do I fix it?
git pull origin main --allow-unrelated-histories — before running it, check the explanation above for what this command discards.
Q. Which tool prints this?
git. It sits under Git, and the message runs to 6 words.