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 to deal with "refusing to merge unrelated histories" error
So before running this to accept ‘unrelated histories’, you may want to confirm you have the right repo’s url. I fixed mine and it started working again. :slight_smile: ... There was an error while loading. Please reload this page. Something went wrong. There was an error while loading. Please reload this page. ... Probably because you did a git init on something like “the same” set of files locally, then tried to merge ... More on github.com
🌐 github.com
19
104
Is keeping both sets of commits possible with merging unrelated histories?
Yes. Add both remotes to the same checkout and then use --allow-unrelated-histories. # create the branch where merging will happen git checkout -b chore/merging_projects origin1/main # merge in the other project git merge --allow-unrelated-histories /main I find it easier to move all files on /main to a new subdir, and then wrangle the files into one location manually, rather than dealing with merge-commits; it's makes it siginificantly easier to track the individual descisions made for each file from that point on, especially on complex projects. More on reddit.com
🌐 r/git
11
1
December 20, 2024
Fix fatal: refusing to merge unrelated histories on git pull
Body I’m getting fatal: refusing to merge unrelated histories when I run git pull on a repo I just initialized locally and connected to an existing GitHub repo. How do I fix this safely? Guidelines... More on github.com
🌐 github.com
3
2
January 2, 2026
How to resolve several merge conflicts when merging feature branch to master without generating a commit for every resolved conflict?
It's the rebases that cause the "multiple" resolve commits; that's the nature of a rebase, it replays each commit on your branch, one-by-one, and you have to resolve any conflicts for each commit on that branch. Merging only involves the "tips" of branches, and so conflicts are resolved in just that one merge commit. Do you need to rebase on top of master? Why? There is an advanced feature called "rerere", for helping to automate repeated rebase conflicts, but honestly it's better to get more practice with simple rebases, or avoid them if you have a branch that is likely to be difficult to resolve (ie. the commits are not "orthogonal" to the master-branch development). More on reddit.com
🌐 r/git
8
3
July 19, 2022
🌐
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
🌐
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.
🌐
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.
🌐
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.
Find elsewhere
🌐
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 - $ git pull origin main ... fatal: ... history. To fix the above error, we need to use the option –allow-unrelated-histories after the git pull <remote> <branch> command, where...
🌐
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 ·
🌐
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 ...
🌐
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.
🌐
GeeksforGeeks
geeksforgeeks.org › git › how-to-merge-unrelated-histories-in-git
How to Merge Unrelated Histories in Git? - GeeksforGeeks
July 23, 2025 - Now, you can merge the unrelated histories by using the --allow-unrelated-histories flag.
🌐
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.
🌐
GitHub
gist.github.com › kingluddite › 7ec82fdfa3700427efa0e5b97196dea6
unrelated-histories.md · GitHub
If you're sure that the branches should be related and you want to proceed with the merge despite the warning, you can use the --allow-unrelated-histories flag as previously mentioned:
🌐
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.
🌐
Reddit
reddit.com › r/git › is keeping both sets of commits possible with merging unrelated histories?
r/git on Reddit: Is keeping both sets of commits possible with merging unrelated histories?
December 20, 2024 -

Some background. I was working on a dev branch for some analysis software I was working on at my organization, and we wanted to do some live testing but, because of access restrictions we couldn't actually clone it from the remote branch. So, we downloaded the zip and then kept adjusting the code from there.

After that, we initialized git in the extracted folder and set the upstream to be our remote repo so it had a branch there and I thought things were fine. I realized now though while trying to do a pull request that it wasn't fine. Because we started from the zip, it has no common history with dev so it won't allow a merge back into the dev branch.

So now I'm here asking, is there a way to merge back into that dev branch, appending the commits I had since all the changes were made after?

🌐
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 occur when ... as a safety measure. To fix the error, use the --allow-unrelated-histories flag with git merge or git pull, then resolve any conflicts....
🌐
Junian Dev
junian.dev › tech › git-refusing-to-merge-unrelated-histories
How to Fix Git Refusing to Merge Unrelated Histories Issue
May 12, 2026 - The error message fatal: refusing to merge unrelated histories means that the two branches have completely separate histories. Luckily, this is easy to fix. You just need to add the --allow-unrelated-histories option to your merge command.
🌐
Fixdevs
fixdevs.com › home › blog › fix: fatal: refusing to merge unrelated histories
Fix: fatal: refusing to merge unrelated histories - FixDevs
May 22, 2026 - The risk is not data loss, it’s merging in a history you didn’t intend to. Before applying the flag blindly, prove the histories are unrelated. Run: ... 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.