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
git-scm.com › docs › git-merge
Git - git-merge Documentation
Automatically create a temporary stash entry before the operation begins, record it in the ref MERGE_AUTOSTASH and apply it after the operation ends. This means that you can run the operation on a dirty worktree. However, use with care: the final stash application after a successful merge might result in non-trivial conflicts. --allow-unrelated-histories ·
🌐
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.
🌐
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?

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 - # Fetch the remote git fetch origin # Merge allowing unrelated histories git merge origin/main --allow-unrelated-histories # If no file name conflicts, merge completes automatically # Both sets of files now exist in your repo
🌐
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.
🌐
Atlassian
jira.atlassian.com › browse › BCLOUD-15952
Support Git merge for branches with unrelated histories
In the DevTools logs we will see an error: " Error: fatal: refusing to merge unrelated histories" Workaround is: do the merge locally by running: git pull origin master --allow-unrelated-histories git merge origin origin/master add and commit pit push origin master
🌐
Better Programming
betterprogramming.pub › when-projects-collide-combining-two-unrelated-git-repositories-414fba42ff3d
Combining Unrelated Git Repositories: When Projects Collide! | by Sebastian Royer | Better Programming
May 10, 2022 - 1 cd path/to/project-b 2 git remote add project-a /path/to/project-a 3 git fetch project-a --tags 4 git merge --allow-unrelated-histories project-a/master # or whichever branch you want to merge 5 git remote remove project-a
🌐
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 - Here the git command will look something like this: git pull origin master --allow-unrelated-histories. You can substitute origin with the remote repository you are pulling from. You can also replace the master branch with whatever branch you ...
🌐
Sentry
sentry.io › sentry answers › git › merge branches with unrelated histories in git
Merge branches with unrelated histories in Git | Sentry
July 15, 2023 - Reclone the remote version of the ... before attempting the merge again. If we are attempting to combine two separate codebases, we must pass the flag --allow-unrelated-histories to git merge:...
🌐
GeeksforGeeks
geeksforgeeks.org › git › how-to-merge-unrelated-histories-in-git
How to Merge Unrelated Histories in Git? - GeeksforGeeks
July 23, 2025 - Merging unrelated histories in ... right steps. By using the --allow-unrelated-histories flag, you can combine projects or branches with different histories, enabling better project management and integration....
🌐
TutorialsPoint
tutorialspoint.com › article › how-to-solve-refusing-to-merge-unrelated-histories-in-git
How to solve Refusing to Merge Unrelated histories in Git?
August 8, 2023 - This command fetches the remote changes and merges them into the current branch. Here's an example ? git pull origin <branch-name> --allow-unrelated-histories
🌐
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
This usually happens when you're trying to merge or rebase branches that were created independently and don't share any commit history. To resolve this issue, you can pass the --allow-unrelated-histories option to the git merge or git rebase command.
🌐
JetBrains
youtrack.jetbrains.com › issue › IJPL-72863 › request-git-merge-pull-support-allow-unrelated-histories-options
[request] git merge/pull support `--allow-unrelated-histories ...
{{ (>_<) }} This version of your browser is not supported. Try upgrading to the latest stable version. Something went seriously wrong
🌐
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 - This can be resolved by using the --allow-unrelated-histories flag with the git rebase or git merge commands. Alternatively, you can perform a manual merge to integrate the changes.
🌐
YouTube
youtube.com › watch
GIT - Unrelated Histories #VisualGit - YouTube
Deep dive into Git 'unrelated histories' using real-time visualization. We look at how this situation can occur and then also look to provide a fix in order ...
Published   October 7, 2023