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 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
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
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 merging in azure pipeline
Spitballing here in my phone, but thr checkout may do a git clone - - depth 0 meaning there is no history to be used in the merge. Something to look into. More on reddit.com
🌐 r/azuredevops
2
1
August 5, 2024
People also ask

Can I use `--allow-unrelated-histories` with `git pull`?
Yes, you can use `--allow-unrelated-histories` with `git pull` to fetch and merge changes from a remote repository with a different commit history.
🌐
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 ...
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 ...
🌐
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....
🌐
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
19 hours 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 “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).
🌐
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 - ... Merging unrelated histories can result in a confusing commit graph. Ensure the branches you're merging are related to your project. How can I prevent 'fatal: refusing to merge unrelated histories' errors?
Find elsewhere
🌐
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
The "refusing to merge unrelated histories" error typically occurs when you're trying to merge or rebase branches that have diverged and have no common ancestor. This usually happens when you're trying to merge or rebase branches that were created ...
🌐
Edureka Community
edureka.co › home › community › categories › devops & agile › git & github › fatal refusing to merge unrelated histories
fatal refusing to merge unrelated histories | Edureka Community
April 10, 2020 - Hi Guys, While trying to combine an existing repository, with a remote repository using git pull command, ... . How to solve this error? Thank You
🌐
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 ...
🌐
Medium
medium.com › @jeevankc17 › fatal-refusing-to-merge-unrelated-histories-git-github-aef8a171a53d
“fatal: refusing to merge unrelated histories” -(git-github) | by Jeevan KC | Medium
July 8, 2023 - The error message you received, “fatal: refusing to merge unrelated histories,” occurs when you try to merge two branches that have diverged and do not share a common commit history.
🌐
Medium
bryantson.medium.com › how-to-fix-fatal-refusing-to-merge-unrelated-histories-in-git-738ce02e50e3
How to fix “fatal: refusing to merge unrelated histories” in git | by Bryant Jimin Son | Medium
April 13, 2023 - The easiest way to solve is by passing--allow-unrelated-histories option in git pull. git pull origin main — allow-unrelated-histories · However, if you want an alternative route, you can stash with git stash command, git pull, then pop with ...
🌐
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.
🌐
Namehero
namehero.com › blog › resolving-the-fatal-refusing-to-merge-unrelated-histories-error
Resolving the "Fatal: Refusing to Merge Unrelated Histories" Error
April 9, 2025 - In git, the “fatal: refusing to merge unrelated histories” error occurs when you merge two branches with no common ancestor and git doesn’t know where to begin the merge. This error doesn’t occur in the normal git workflow, but it can happen when you try to combine two unrelated git projects into a single one, or you’re trying to add some changes to a remote project for the first time without doing a pull...
🌐
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.
🌐
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 - To fix the above error, we need to use the option –allow-unrelated-histories after the git pull <remote> <branch> command, where · <remote> is the remote repository URL or its short-name origin · <branch> is the branch name that we’d like ...
🌐
Tencent Cloud
cloud.tencent.com › developer › article › 1640651
git 出现 fatal: refusing to merge unrelated histories 错误 - 腾讯云开发者社区-腾讯云
git clone远程仓库到本地,将需要推送的内容放到该仓库下 , 然后提交上去 , 这样算是一次update操作 ... 后面加上 --allow-unrelated-histories , 把两段不相干的分支进行强行合;这里可能会进入一个编辑页面,只需要先ESC,然后敲:q!
🌐
Shkodenko Taras
shkodenko.com › home › server configuration › git › how to resolve “fatal: refusing to merge unrelated histories” in git and transition to remote repositories
How to Resolve “fatal: refusing to merge unrelated histories” in Git and Transition to Remote Repositories | Shkodenko Taras
December 10, 2024 - A remote repository is created (e.g., on GitHub or GitLab) and populated independently. When you attempt a git pull, Git refuses to merge these distinct histories by default to avoid unintentional overwrites.
🌐
GeeksforGeeks
geeksforgeeks.org › git › how-to-fix-git-refusing-to-merge-unrelated-histories-on-rebase
How to Fix - Git Refusing to Merge Unrelated Histories on Rebase? - GeeksforGeeks
May 27, 2024 - The "refusing to merge unrelated histories" error in Git occurs when you try to rebase or merge branches that do not share a common history. This can be resolved by using the --allow-unrelated-histories flag with the git rebase or git merge commands.