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
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 ...
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 ...
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 ...
🌐
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 - fatal: refusing to merge unrelated ... history. To fix the above error, we need to use the option –allow-unrelated-histories after the git pull <remote> <branch> command, where...
🌐
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.
Find elsewhere
🌐
Tim Mousk
timmousk.com › blog › git-refusing-to-merge-unrelated-histories
How To Fix “fatal: refusing to merge unrelated histories” in Git? – Tim Mouskhelichvili
March 12, 2023 - To fix the "fatal: refusing to merge unrelated histories" error in Git, use the git pull command like so: bashgit pull origin main --allow-unrelated-histories
🌐
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 - Yes, you can use `--allow-unrelated-histories` with `git pull` to fetch and merge changes from a remote repository with a different commit history.
🌐
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 - One way to solve the issue is to use the --allow-unrelated-histories git flag. Here the git command will look something like this: git pull origin master --allow-unrelated-histories.
🌐
GitHub
gist.github.com › kingluddite › 7ec82fdfa3700427efa0e5b97196dea6
unrelated-histories.md · GitHub
If you're certain that you want to merge the unrelated histories, you can force Git to do so with the --allow-unrelated-histories flag: git pull origin <branch-name> --allow-unrelated-histories
🌐
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 - This is because Git doesn’t know if the remote repository is compatible with your current repository. We’ve done enough talking. To solve this issue, you can use the --allow-unrelated-histories flag when pulling data from a repository:
🌐
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.
🌐
Git Scripts
gitscripts.com › git-pull-allow-unrelated-histories
Git Pull Allow Unrelated Histories: A Quick Guide
October 10, 2025 - The `git pull --allow-unrelated-histories` command is used to merge two unrelated Git repositories that do not share a common commit history.
🌐
Educative
educative.io › answers › the-fatal-refusing-to-merge-unrelated-histories-git-error
The “fatal: refusing to merge unrelated histories” Git error
You have created a new repository, ... has no idea how the two projects are related. The error is resolved by toggling the allow-unrelated-histories switch....
🌐
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 - To resolve this issue, you need to explicitly tell Git that you want to merge these unrelated histories. You can do this by using the --allow-unrelated-histories option with the git merge or git pull command.
🌐
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:
🌐
GitHub
github.com › gitpython-developers › GitPython › issues › 560
Ability to make pull --allow-unrelated-histories · Issue #560 · gitpython-developers/GitPython
December 20, 2016 - 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.
Author   gitpython-developers
🌐
Datree
datree.io › resources › git-error-fatal-refusing-to-merge-unrelated-histories
Fix Git Error - Fatal: refusing to merge unrelated histories - Datree.io | Datree.io
November 21, 2019 - In short, the solution is to use the flag --allow-unrelated-histories. If the error occurred while using $git pull then this is an example:
🌐
LabEx
labex.io › tutorials › git-how-to-resolve-refusing-to-merge-unrelated-histories-error-in-git-417643
How to resolve 'refusing to merge unrelated histories' error in Git | LabEx
To resolve the "refusing to merge unrelated histories" error, you can use the --allow-unrelated-histories option when merging the repositories. This option tells Git to proceed with the merge, even if the two repositories have completely different ...