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
Discussions

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
Refused to merge unrelated histories error from git
SO here’s the error From https://github.com/AverageGuy/TaskSched fae94dc..69acc07 main -> origin/main fatal: refusing to merge unrelated histories VCSBaseException: VCS: Could not process command ['git', 'pull', '--recurse-submodules'] So I found a site that discussed the error and did the ... More on community.platformio.org
🌐 community.platformio.org
1
0
January 17, 2024
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
Merging unrelated histories
Since you changed the original commit with your ament, it makes sense to force push now, as you wanted to change the original commit. git push --force-with-lease More on reddit.com
🌐 r/git
12
6
November 21, 2020
🌐
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....
🌐
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:
🌐
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.
Find elsewhere
🌐
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 - # Create local repo with initial commit mkdir my-project cd my-project git init echo "# My Project" > README.md git add README.md git commit -m "Initial commit" # Add remote that already has commits git remote add origin https://github.com/user/existing-repo.git # Try to pull git pull origin main # fatal: refusing to merge unrelated histories
🌐
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 - In other words, Git believes that the branches are unrelated, and merging them could potentially mix unrelated codebases, leading to chaos. Imagine you have two branches: branchA and branchB. If there is no shared commit or common ancestor between these branches, Git will consider their histories unrelated.
🌐
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 ...
🌐
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:
🌐
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"
Use the --allow-unrelated-histories flag when merging their branches. ... If you have a new local repository and want to pull changes from an existing remote repository, use the --allow-unrelated-histories flag during the pull operation: ... ...
🌐
DEV Community
dev.to › omesha › solving-the-error-fatal-refusing-to-merge-unrelated-histories-491h
Solving the Error - "fatal: refusing to merge unrelated histories" - DEV Community
July 20, 2025 - Git was not able to find the shared base to apply and combine changes. So, it refused to merge by default as a safety measure, by throwing an Error. As I really wanted to combine these repositories, I used a git command to allow the merge with a git option --allow-unrelated-histories
🌐
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.
🌐
Fixdevs
fixdevs.com › home › blog › fix: fatal: refusing to merge unrelated histories
Fix: fatal: refusing to merge unrelated histories - FixDevs
May 22, 2026 - The risk is not data loss, it’s merging in a history you didn’t intend to. Before applying the flag blindly, prove the histories are unrelated. Run: ... If this command prints nothing (or returns a non-zero exit code with the message “fatal: Not a valid commit name”), then the two refs share no common ancestor and --allow-unrelated-histories is the correct tool.
🌐
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.
🌐
GeeksforGeeks
geeksforgeeks.org › git › how-to-fix-git-refusing-to-merge-unrelated-histories
How to Fix Git “Refusing to Merge Unrelated Histories”? - GeeksforGeeks
July 23, 2025 - The "refusing to merge unrelated histories" error occurs because Git tries to ensure that the branches being merged have a common ancestor, a shared commit in their history.
🌐
Megacolorboy
megacolorboy.com › til › posts › how-to-resolve-the-fatal-refusing-to-merge-unrelated-histories-git-error
How to resolve the "fatal: refusing to merge unrelated histories" Git error? | Abdush Shakoor's Weblog
This error shows up when two different projects are merged (i.e. they both could be the same project but unaware of each other's existence and have different commit histories). ... You must have cloned a project and the .git directory must have corrupted or got deleted and at this point, Git ...