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
🌐
Git
git-scm.com › docs › git-merge
Git - git-merge Documentation
Automatically create a temporary stash entry before the operation begins, record it in the ref MERGE_AUTOSTASH and apply it after the operation ends. This means that you can run the operation on a dirty worktree. However, use with care: the final stash application after a successful merge might result in non-trivial conflicts. --allow-unrelated-histories ·
Discussions

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 : ... my computer died suddenly and I bought a new one. Now Github refuses to connect the local repo from my new computer to the online repo saying “refusing to merge unrelated histories”. What do I do ?... More on github.com
🌐 github.com
19
104
🌐
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
1 day 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....
🌐
Graphite
graphite.com › guides › how-to-resolve-git-error-refusing-to-merge-unrelated-histories
How to resolve the Git error "refusing to merge unrelated histories"
Attempt to merge the remote branch (e.g., main) into your local branch (e.g., main) using the --allow-unrelated-histories flag: ... This command tells Git to permit the merge despite the lack of shared history between the branches.
🌐
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 - # Fetch the remote git fetch origin # Merge allowing unrelated histories git merge origin/main --allow-unrelated-histories # If no file name conflicts, merge completes automatically # Both sets of files now exist in your repo
Find elsewhere
🌐
DEV Community
dev.to › donovanrichardson › adding-a-new-remote-and-merging-unrelated-branches-1mkm
Adding a New Remote and Merging Unrelated Branches - DEV Community
August 24, 2020 - But this doesn't mean that Git cannot perform any merge. In fact, all you need to do to merge unrelated branches is to use the flag --allow-unrelated-histories.
🌐
GeeksforGeeks
geeksforgeeks.org › git › how-to-merge-unrelated-histories-in-git
How to Merge Unrelated Histories in Git? - GeeksforGeeks
July 23, 2025 - Attempting a standard merge in such cases results in an error message: ... This safeguard prevents accidental merges of entirely different projects. To bypass this, you need to explicitly tell Git to allow the merge of these unrelated histories.
🌐
GitHub
gist.github.com › kingluddite › 7ec82fdfa3700427efa0e5b97196dea6
unrelated-histories.md · GitHub
It's a safety feature to ensure that you don't accidentally combine projects or branches that should remain separate. Git is essentially saying that it cannot create a meaningful merge with no common base. To proceed with merging unrelated histories, you can use the --allow-unrelated-histories flag ...
🌐
Better Programming
betterprogramming.pub › when-projects-collide-combining-two-unrelated-git-repositories-414fba42ff3d
Combining Unrelated Git Repositories: When Projects Collide! | by Sebastian Royer | Better Programming
May 10, 2022 - 1 cd path/to/project-b 2 git remote add project-a /path/to/project-a 3 git fetch project-a --tags 4 git merge --allow-unrelated-histories project-a/master # or whichever branch you want to merge 5 git remote remove project-a
🌐
Reddit
reddit.com › r/gitlab › how am i supposed to merge these two? when i try to git merge master, i get told "refusing to merge unrelated histories"
r/gitlab on Reddit: How am I supposed to merge these two? when I try to git merge master, I get told "refusing to merge unrelated histories"
March 11, 2022 - Try: git pull origin main --allow-unrelated-histories · and then input the commit message. galacticDaemon • · 4y ago · Please, stop negationism and accept real history. [deleted] • · 4y ago · Comment deleted by user · [deleted] • ...
🌐
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 - Here the git command will look something like this: git pull origin master --allow-unrelated-histories. You can substitute origin with the remote repository you are pulling from. You can also replace the master branch with whatever branch you ...
🌐
Better Stack
betterstack.com › community › questions › git-refusing-to-merge-unrelated-histories-on-rebase
Git Refusing to Merge Unrelated Histories on Rebase | Better Stack Community
This usually happens when you're trying to merge or rebase branches that were created independently and don't share any commit history. To resolve this issue, you can pass the --allow-unrelated-histories option to the git merge or git rebase command.
🌐
Jeff Kreeftmeijer
jeffkreeftmeijer.com › git-combine
Combine Git repositories with unrelated histories
August 9, 2021 - To combine the two repositories, first add the second repository as a remote to the first. Then, run git fetch to fetch its branch information: ... Then, with the remote set up, merge the second repository’s history into the first by using the --allow-unrelated-histories flag:
🌐
Educative
educative.io › answers › the-fatal-refusing-to-merge-unrelated-histories-git-error
The “fatal: refusing to merge unrelated histories” Git error
The error is resolved by toggling the allow-unrelated-histories switch. After a git pull or git merge command, add the following tag:
🌐
Wouter J
wouterj.nl › 2025 › 12 › merging-unrelated-repositories
Merging Unrelated Projects using Git ~ Wouter J
December 3, 2025 - Using the --allow-unrelated-histories flag means you no longer have a linear Git history; it consists of 2 separate branches at the start. Use it for the niche use-case, and don’t make this flag your common hammer to fix Git merge errors.
🌐
Sentry
sentry.io › sentry answers › git › merge branches with unrelated histories in git
Merge branches with unrelated histories in Git | Sentry
July 15, 2023 - Reclone the remote version of the ... before attempting the merge again. If we are attempting to combine two separate codebases, we must pass the flag --allow-unrelated-histories to git merge:...
🌐
Junian Dev
junian.dev › tech › git-refusing-to-merge-unrelated-histories
How to Fix Git Refusing to Merge Unrelated Histories Issue
May 12, 2026 - The error message fatal: refusing to merge unrelated histories means that the two branches have completely separate histories. Luckily, this is easy to fix. You just need to add the --allow-unrelated-histories option to your merge command.
🌐
Fixdevs
fixdevs.com › home › blog › fix: fatal: refusing to merge unrelated histories
Fix: fatal: refusing to merge unrelated histories - FixDevs
May 22, 2026 - Knowing your Git version saves ... repo locally and are pulling from a remote for the first time: ... Git will merge the two unrelated histories together....