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

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
What can cause Git's "unrelated histories" (other than force-pushing)?
Copying all the files into a new folder, then running git init / git remote add / etc More on reddit.com
🌐 r/git
10
8
June 22, 2020
🌐
Medium
spences10.medium.com › git-allow-unrelated-histories-a39a3814b981
Git ` — allow-unrelated-histories` | by Scott Spence | Medium
September 30, 2020 - Git ` — allow-unrelated-histories` How to combine two separate unrelated Git repositories into one with single history timeline. Just adding a quick note on this… I had a project that started off …
🌐
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"
... If you are combining two distinct repositories, follow similar steps but ensure that you add both repositories as remotes and fetch changes from each. Use the --allow-unrelated-histories flag when merging their 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 - The merge commit has two parents, connecting the previously separate histories. Instead of creating a local repo first, clone the remote. # Instead of: git init git remote add origin <url> git pull # fails with unrelated histories # Do this: git clone <url> # Now local and remote share history
Find elsewhere
🌐
GitHub
gist.github.com › kingluddite › 7ec82fdfa3700427efa0e5b97196dea6
unrelated-histories.md · GitHub
Different Root Commits: When you attempt to merge two branches, Git assumes that they share a common ancestor, a common root commit. However, if the branches have entirely different histories with no common ancestor, Git sees them as unrelated.
🌐
Reddit
reddit.com › r/git › merging unrelated histories
r/git on Reddit: Merging unrelated histories
November 21, 2020 -

I created the following repository on GitHub: https://github.com/james/test.git.

Then I proceeded with:

user@guest:~/.../gits$ git config --global init.defaultBranch main
user@guest:~/.../gits$ mkdir test && cd test
user@guest:~/.../test$ echo "# test" >> README.md
user@guest:~/.../test$ git init
user@guest:~/.../test$ git add README.md
user@guest:~/.../test$ git commit -m "First commit"
user@guest:~/.../test$ git remote add origin https://github.com/james/test.git
user@guest:~/.../test$ git push -u origin main

And then:

user@guest:~/.../test$ git commit --amend
user@guest:~/.../test$ git log --oneline --graph --all
* ca82a6d (HEAD -> main) First commit
* 085bb3b (origin/main) First commit
user@guest:~/.../test$ git merge origin/main
fatal: refusing to merge unrelated histories

What did I do wrong and what is the best solution in this case?

🌐
GeeksforGeeks
geeksforgeeks.org › git › how-to-merge-unrelated-histories-in-git
How to Merge Unrelated Histories in Git? - GeeksforGeeks
July 23, 2025 - Unrelated histories occur when two branches or repositories do not share a common commit ancestor, which can happen when combining projects, integrating different repositories, or starting fresh with new histories.
🌐
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 ...
🌐
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).
🌐
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 - In my experience, here are tips that can help you better resolve and prevent the `fatal: refusing to merge unrelated histories` error: Ensure both repositories share a common ancestor before merging to avoid unrelated history conflicts. Regularly check the `.git` directory for corruption, which can cause merging issues.
🌐
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
git-scm.com › docs › git-merge
Git - git-merge Documentation
--allow-unrelated-histories · By default, git merge command refuses to merge histories that do not share a common ancestor. This option can be used to override this safety when merging histories of two projects that started their lives independently. As that is a very rare occasion, no ...
🌐
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 - In other words, Git believes that ... two branches: branchA and branchB. If there is no shared commit or common ancestor between these branches, Git will consider their histories unrelated....
🌐
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:
🌐
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
By using the --allow-unrelated-histories option, you're explicitly telling Git to allow the merge or rebase operation even if the branches have unrelated histories.
🌐
CodeGenes
codegenes.net › blog › git-is-refusing-to-merge-unrelated-histories-what-are-unrelated-histories
Git 'Refusing to Merge Unrelated Histories' Error: What Are Unrelated Histories? — codegenes.net
Unrelated histories typically arise in two scenarios: Merging a Local Repo with a New Remote Repo Suppose you initialize a Git repository locally (git init), add files, and commit changes.
🌐
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.
🌐
Reddit
reddit.com › r/git › what can cause git's "unrelated histories" (other than force-pushing)?
r/git on Reddit: What can cause Git's "unrelated histories" (other than force-pushing)?
June 22, 2020 -

Hi,

I've been working on a website with someone for a few weeks, and every now-and-then we come across an issue with unrelated histories.

I know my way around Git, for the most part, but the other developer doesn't, so I've mostly been giving the instructions. However, there was a time where he had merge conflicts and decided to force-push to our GitHub repo. Obviously, this messed everything up, and to be honest I forgot that force-pushing was even a thing Git could do.

Anyway, it's happened again. And this time I don't think it's due to a force-push... even though there's only 1 commit in git log.

So my question is, what else can cause unrelated histories in Git?