You can use --allow-unrelated-histories to force the merge to happen.

The reason behind this is that default behavior has changed since Git 2.9:

"git merge" used to allow merging two branches that have no common base by default, which led to a brand new history of an existing project created and then get pulled by an unsuspecting maintainer, which allowed an unnecessary parallel history merged into the existing project. The command has been taught not to allow this by default, with an escape hatch --allow-unrelated-histories option to be used in a rare event that merges histories of two projects that started their lives independently.

See the Git release changelog for more information.

More information can be found in this answer.

Answer from blue112 on Stack Overflow
🌐
OneUptime
oneuptime.com › home › blog › how to fix 'fatal: refusing to merge unrelated histories'
How to Fix 'Fatal: refusing to merge unrelated histories'
January 24, 2026 - # You had a local clone cd existing-local-clone # Someone deleted and recreated the remote repo git pull # fatal: refusing to merge unrelated histories # The new remote has completely new commits
Discussions

Gitlab runner 13.1.1 checks out a commit and not my branch
(probably the most recent one) This means that the runner cannot merge the branch with the master branch to perform a coherence check because it results in fatal: refusing to merge unrelated histories *When I have the runner execute git status it prints that HEAD is detached. More on forum.gitlab.com
🌐 forum.gitlab.com
3
0
July 13, 2020
How am I supposed to merge these two? when I try to git merge master, I get told "refusing to merge unrelated histories"
The —allow-unrelated-histories param might do the job. See this for more detailed explanation More on reddit.com
🌐 r/gitlab
20
5
March 11, 2022
How to deal with "refusing to merge unrelated histories" error
Short version of my question : For years, I have been using a simple, single one-branch, one-contributor public online Github repo. A few days ago my computer died suddenly and I bought a new one. ... More on github.com
🌐 github.com
19
104
github - Git failed with a fatal error, refusing to merge unrelated histories with Git push - Stack Overflow
In GitLab you have to unprotect your master branch (in settings → repository) Also if your Git is too old, the --allow-unrelated-histories might not be implemented. You could do the push --force origin master, but remember that it might mess up not even your repository. Also all remote clients might have to pull --force or clone again. See in (long discussion) Git refusing to merge ... More on stackoverflow.com
🌐 stackoverflow.com
June 14, 2020
People also ask

How to Fix "fatal: refusing to merge unrelated histories" in Git
This error appears when you try to merge two Git repositories that share no common ancestor — their histories are completely unrelated from Git's perspective. A common trigger is creating a new repository on GitHub with an auto-generated README or LICENSE file and then trying to push a separate, pre-existing local repository to it. To resolve it, run git pull origin main --allow-unrelated-histories, which tells Git to proceed with the merge despite the lack of a shared ancestor. Git will then attempt to combine the two histories, potentially surfacing conflicts if both sides contain files with
🌐
git-tower.com
git-tower.com › learn › git faq › how to fix "fatal: refusing to merge unrelated histories" in git
How to Fix "fatal: refusing to merge unrelated histories" in Git ...
How can I prevent 'fatal: refusing to merge unrelated histories' errors?
Ensure your branches share a common commit history. When working with forks or split repositories, establish a common ancestor or use patch files to apply changes instead of directly merging or rebasing.
🌐
blog.openreplay.com
blog.openreplay.com › openreplay blog › how to fix 'fatal: refusing to merge unrelated histories' during git rebase
How to Fix 'fatal: refusing to merge unrelated histories' During ...
What happens if I merge unrelated histories?
Merging unrelated histories can result in a confusing commit graph. Ensure the branches you're merging are related to your project.
🌐
blog.openreplay.com
blog.openreplay.com › openreplay blog › how to fix 'fatal: refusing to merge unrelated histories' during git rebase
How to Fix 'fatal: refusing to merge unrelated histories' During ...
🌐
Mazer.dev
mazer.dev › en › git › troubleshooting › how-to-fix-git-fatal-error-refusing-to-merge-unrelated-histories
How to fix Git fatal error: refusing to merge unrelated histories - Mazer.dev
October 1, 2022 - To solve this error just use the option allow-unrelated-histories. To allow GIT to make the merge of two projects with different histories, pass the parameter --uslow-unreard-histories when making the pull, like this:
🌐
GitLab
forum.gitlab.com › gitlab ci/cd
Gitlab runner 13.1.1 checks out a commit and not my branch - GitLab CI/CD - GitLab Forum
July 13, 2020 - (probably the most recent one) This means that the runner cannot merge the branch with the master branch to perform a coherence check because it results in fatal: refusing to merge unrelated histories *When I have the runner execute git status ...
🌐
Git Tower
git-tower.com › learn › git faq › how to fix "fatal: refusing to merge unrelated histories" in git
How to Fix "fatal: refusing to merge unrelated histories" in Git | Learn Version Control with Git
2 days ago - It is good practice to first ... so, the solution is simple. To fix the error, you can use the --allow-unrelated-histories option when running the git merge command....
Find elsewhere
🌐
OpenReplay
blog.openreplay.com › openreplay blog › how to fix 'fatal: refusing to merge unrelated histories' during git rebase
How to Fix 'fatal: refusing to merge unrelated histories' During Git Rebase
December 2, 2024 - Ensure the branches you’re merging or rebasing are related to your project. The “fatal: refusing to merge unrelated histories” error happens when you try to merge or rebase branches that have no common commit history.
🌐
Medium
medium.com › @sahilali › understanding-and-resolving-fatal-refusing-to-merge-unrelated-histories-in-git-8701d07624c5
Understanding and Resolving “fatal: refusing to merge unrelated histories” in Git | by Sahil Ali | Medium
September 30, 2023 - The “fatal: refusing to merge ... a Git merge operation. It occurs when Git detects that the branches you are attempting to merge have diverged significantly and lack a common ancestor commit....
🌐
TechDirectArchive
techdirectarchive.com › home › version control system › how to fix fatal git error refusing to merge unrelated histories
How to Fix Fatal Git Error Refusing to Merge Unrelated Histories - TechDirectArchive
December 16, 2023 - Resolve Fix Fatal Git Error Refusing to Merge Unrelated Histories issue in simple steps. Get past the Git error hassle withnthis blogpost
🌐
DEV Community
dev.to › abisaifredrick › fatal-refusing-to-merge-unrelated-histories-3bb4
fatal: refusing to merge unrelated histories - DEV Community
August 12, 2024 - Create a new empty commit that connects unrelated branches then merge those branches. ... When setting up a new repository, it’s advisable to initialize it using an existing project.
🌐
Career Karma
careerkarma.com › blog › git › how to solve fatal: refusing to merge unrelated histories
How to Solve fatal: refusing to merge unrelated histories | Career Karma
December 1, 2023 - The fatal: refusing to merge unrelated histories git error can be resolved using the --allow-unrelated-histories flag. On Career Karma, learn how to resolve this common error.
🌐
Educative
educative.io › answers › the-fatal-refusing-to-merge-unrelated-histories-git-error
The “fatal: refusing to merge unrelated histories” Git error
The “fatal: refusing to merge unrelated histories” Git error occurs when two unrelated projects are merged (i.e., projects that are not aware of each other’s existence and have mismatching commit histories).
🌐
DEV Community
dev.to › wlarch › git-error-fatal-refusing-to-merge-unrelated-histories-explanation-3f90
Git error “fatal: refusing to merge unrelated histories” explanation - DEV Community
January 25, 2021 - You can solve this issue by adding the allow-unrelated-histories flag. After executing git pull or git merge, add the following flag:
Top answer
1 of 3
2

Basic tip: pull from clean source, copy changed files, etc.

In GitLab you have to unprotect your master branch (in settingsrepository)

Also if your Git is too old, the --allow-unrelated-histories might not be implemented. You could do the push --force origin master, but remember that it might mess up not even your repository. Also all remote clients might have to pull --force or clone again.

See in (long discussion) Git refusing to merge unrelated histories on rebase.

2 of 3
1

The --allow-unrelated-histories flag applies only to merging. Since git push does not merge (ever), it has no --allow-unrelated-histories option. (Contrast this with the git pull command, which does sometimes—well, quite often, really—run git merge.)

I tried changing the username of all commits ...

You cannot change anything about any existing commit. All commits are 100% read-only.

What you can do is take a series of commits that have something about them that you don't like—such as the name and/or email address of the author and/or committer—and copy them to new and improved commits that are otherwise the same, but have this issue corrected. It appears that this must be what you did, because:

... [after] the pull command ... every commit is simply doubled with the correct and incorrect username.

This doubling is, of course, exactly what you did when you made corrected commits. You told your Git to discard the old (incorrect) commits in favor of the new improved ones, and it did. But another Git repository—the one over on GitHub—still had, and has, the incorrect commits. You then told your Git to obtain any commits they have, that you don't—which in this case were the commits you'd just discarded—and then join them up with the commits you have that they don't, which in this case are your new-and-improved replacements.

You must discard the joining-up merge, typically via git reset. This gets you back to the situation in which you have replaced your old-and-incorrect commits with your new-and-improved copies—i.e., back to where you were before you ran git pull. You are now back where you were: you still need to convince the Git over at GitHub to discard its old-and-incorrect commits in favor of your new-and-improved ones.

To do that, you must use git push --force or git push --force-with-lease. You must also have permission to do this, though if the GitHub repository is under your control, this is either already the case, or easy to set up (you have to tell GitHub what to forbid, so if you did not forbid yourself from force-push earlier, you need not change anything now).

Note that discarding any given commit necessarily discards all subsequent commits. So if there are additional commits you'd like to keep, you must first copy those to new-and-improved commits, whose improvement is that they append to your existing new-and-improved commits.

🌐
Junian Dev
junian.dev › tech › git-refusing-to-merge-unrelated-histories
How to Fix Git Refusing to Merge Unrelated Histories Issue
May 12, 2026 - You just need to add the --allow-unrelated-histories option to your merge command. ... By default, the git merge command refuses to merge histories that do not share a common ancestor.
🌐
Komodor
komodor.com › home › articles › how to fix ‘fatal: refusing to merge unrelated histories’ git error
How to fix 'fatal: refusing to merge unrelated histories' Git error
September 15, 2025 - The alternative (and longer) way of fixing the fatal: refusing to merge unrelated histories issues is to unstage your current commits, stash them, clone your required remote repository, and then place your stashed branch contents into the new clone.
🌐
Baeldung
baeldung.com › home › git › how to fix git “refusing to merge unrelated histories”
How to Fix Git “Refusing to Merge Unrelated Histories” | Baeldung on Ops
February 6, 2024 - The –allow-unrelated-histories option will tell the Git that we allow merging branches with no common history base, which then should finish the merge without errors. We should note that for the Git version 2.9 or older, this option is not ...