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 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....
Discussions

fatal: refusing to merge unrelated histories
To make the vscode-docs repository smaller #1789 (it was over 2 GB), the historical content has been moved to https://github.com/Microsoft/vscode-docs-archive and past history removed. If you try t... More on github.com
🌐 github.com
1
March 19, 2019
Visual Studio Code does not accept the changes I make when resolving merge conflicts
Select Topic Area Question Body I've been working on trying to merge a child branch back into the default branch, since yesterday. One person used some method to re-write the git history in the chi... More on github.com
🌐 github.com
1
2
May 9, 2025
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
People also ask

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 ...
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 ...
🌐
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:
🌐
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 - To resolve the error, use the --allow-unrelated-histories flag cautiously. Alternatives include manually connecting histories or using patch files. Ensure the branches you’re merging or rebasing are related to your project.
🌐
GitHub
github.com › microsoft › vscode-docs › issues › 2471
fatal: refusing to merge unrelated histories · Issue #2471 · microsoft/vscode-docs
March 19, 2019 - To make the vscode-docs repository smaller #1789 (it was over 2 GB), the historical content has been moved to https://github.com/Microsoft/vscode-docs-archive and past history removed. If you try to pull from an existing local vscode-docs repo, you will see "fatal: refusing to merge unrelated histories".
Author   microsoft
Find elsewhere
🌐
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.
🌐
Medium
sahilali.medium.com › 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....
🌐
IQCode
iqcode.com › code › shell › refusing-to-merge-unrelated-histories
refusing to merge unrelated histories Code Example
August 28, 2021 - merge unrelated histories fix fatal: ... to merge unrelated histories git unable to merge unrelated histories refusing to merge unrelated histories github failed to merge unrelated histories visual studio Git failed with a fatal error....
🌐
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. This approach links their histories, helping to prevent the issue of unrelated histories.
🌐
Mark Pelf
markpelf.com › 1437 › git-error-refusing-to-merge-unrelated-histories
Git – Error: refusing to merge unrelated histories - Mark Pelf - Blog
August 3, 2022 - Explanation of problem and instructions are at [2]. We need to run “git merge <branch-name> --allow-unrelated-histories” · So, you can open GitBash from SourceTree (Terminal button), and execute the command.
🌐
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 - When two repositories or branches do not share any commits, Git treats them as having unrelated histories and refuses to merge them by default to prevent potential conflicts and confusion.
🌐
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 - During my exercise, I had one conflict: README.md existed in both repositories, and it was not possible for Git to automatically merge the content of each file. In my situation, I needed only the remote README.md, so I used Visual Studio Code's user-friendly merge conflict tool to resolve the conflicts. After fixing the merge conflicts, all you have to do to resolve the unrelated histories is commit.
🌐
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 - # Pull with unrelated histories ... --abort · The "refusing to merge unrelated histories" error protects you from accidentally combining separate projects....
🌐
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 › 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:
🌐
CodeProject
codeproject.com › Tips › 5339590 › Git-Error-Refusing-to-Merge-Unrelated-Histories
Git – Error: Refusing to Merge Unrelated Histories
August 12, 2022 - Disclaimer: References to any specific company, product or services on this Site are not controlled by GoDaddy.com LLC and do not constitute or imply its association with or endorsement of third party advertisers
🌐
Generalist Programmer
generalistprogrammer.com › home › errors › git › fatal: refusing to merge unrelated histories
fatal: refusing to merge unrelated histories - Causes & Solutions | Git Error Guide
November 21, 2025 - ▸GitKraken - Visualizes branch relationships and unrelated histories · ▸Sourcetree - Shows commit graph to identify unrelated histories ... Error Failed To Push Some Refs→Merge Conflict Content→Fatal Not A Git Repository→Fatal Remote Origin Already Exists→
🌐
Fixdevs
fixdevs.com › home › blog › fix: fatal: refusing to merge unrelated histories
Fix: fatal: refusing to merge unrelated histories - FixDevs
May 22, 2026 - 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. If it does print a commit SHA, the real problem is different — usually a force-push that rewrote history, in which case you want a different remediation such as git reset --hard origin/main (after stashing your work) rather than an unrelated-history merge. ... This visualises whether the two branches actually meet anywhere.