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

github - How to fix "refusing to merge unrelated histories"? I have tried "git pull origin master --allow-unrelated-histories" - Stack Overflow
I am trying to pull everything from my dev branch to master but I am getting "Already up to date". So when I tried to merge them together, i get, "fatal: refusing to merge unrelated histories". Can someone please help me. ... You can use --allow-unrelated-histories, as morty answered. But watch out: this may not do what you want. It depends on what you want, and what's in the two commits you'll choose this way. git ... More on stackoverflow.com
🌐 stackoverflow.com
I need to understand Git pull origin master --allow-unrelated-histories better - Stack Overflow
These are all the commands I ran ... to the remote repository (one of these commands is the command that I need to understand, git pull origin master --allow-unrelated-histories):... More on stackoverflow.com
🌐 stackoverflow.com
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
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
🌐
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 - One way to solve the issue is to use the --allow-unrelated-histories git flag. Here the git command will look something like this: git pull origin master --allow-unrelated-histories.
🌐
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: git pull origin master --allow-unrelated-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 - $ 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...
Find elsewhere
🌐
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 - We’ve done enough talking. To solve this issue, you can use the --allow-unrelated-histories flag when pulling data from a repository: Git pull origin master –allow-unrelated-histories
🌐
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 git pull origin main --allow-unrelated-histories # Merge with unrelated histories git merge branch-name --allow-unrelated-histories # Fetch first to inspect before merging git fetch origin git log origin/main ...
Top answer
1 of 2
4

You can use --allow-unrelated-histories, as morty answered. But watch out: this may not do what you want. It depends on what you want, and what's in the two commits you'll choose this way.

git merge works by comparing the merge base commit with the two particular other commits that you select. You select one of the two commits you want to use by checking it out:

git checkout master

and the other with an argument to git merge:

git merge wip269

for instance.

The merge base, however, is determined by the history, and history, in Git, consists of the commits in the repository, as linked by those commits themselves. This is where the command is failing, because the histories are not related to each other: there is no merge base commit.

If the histories were related, this:

          A--B--...--H   <-- master
         /
...--o--*
         \
          P--Q--...--W   <-- wip269

might be a good way to draw the commit graph. From this drawing, you could see that the history in master starts (or ends) at commit H and works backwards to A, and then to commit * and further back; and history in wip269 starts (or end) at commit W, then works back to P and on to * and further back.

Commit * would then be the merge base. The merge base is defined as the best common commit. The best one is obviously *—commits that come before it would work too, but it seems better to stick with the one closest to the two branch-ends you started from. The way git merge works is to compare the files in the merge base to the files in your current commit—here H—to see what you changed, then compare those same files in the same merge base to the files in their commit (W) to see what they changed. Having found what you both changed, Git can combine the changes.

The problem here is that your history does not look anything like this. It probably looks something like this:

A--B--...--H   <-- master (HEAD)

P--Q--...--W   <-- wip269

That is, starting at H and working backwards, Git eventually arrives at commit A, which is a root commit: it has no previous history. Meanwhile, starting at W and working backwards, Git eventually arrives at commit P, which is also a root commit. There is no shared commit that is on both branches.

Using --allow-unrelated-histories tells git merge: OK, if there's no common commit, play a pretend game that there is: pretend that there is a common commit that contains no files at all, and use that as the merge base.

This means that what you changed is: you invented every file from scratch. Meanwhile, what they changed is that they, too, invented every file from scratch.

Where the invented files have different names, Git will take the new files. Where they have the same names, Git will declare an add/add conflict and leave you to figure out what should go in the file with that name.

If and when you resolve all such conflicts and commit—or if there are no conflicts—Git will make a new merge commit whose parents are both H and W:

A--B--...--H
            \
             X   <-- master (HEAD)
            /
P--Q--...--W   <-- wip269

and now commits P through W are on both branches. Commits A through H, plus X, are (only) on master. If you move the name wip269 so that it, too, points to new commit X, all 17 commits will be on both branches; or you can delete the name wip269 now, if you're done with it, after which all commits are only on master.

Side note on git pull

All git pull does is run git fetch, then immediately run a second Git command. The second command is usually—and is in your case—git pull. So you can do this with git pull (which can pass --allow-unrelated-histories to its git merge), but you might as well do it with git merge at this point—you've probably already done any necessary fetch.

2 of 2
1

dev and master branches have 'unrelated histories' which means they have no common base by default.
git merge does not allow two branches with unrelated histories to be merged to prevent parallel histories.

You can use --allow-unrelated-histories to force the merge.

🌐
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 …
🌐
Mkyong
mkyong.com › home › git › git pull – refusing to merge unrelated histories
Git pull - refusing to merge unrelated histories - Mkyong.com
December 14, 2018 - Add --allow-unrelated-histories to solve the Git fatal error – “refusing to merge unrelated histories” ... $ git pull origin master From https://github.com/mkyong/java-concurrency * branch master -> FETCH_HEAD fatal: refusing to merge ...
🌐
Reddit
reddit.com › r/gitlab › how am i supposed to merge these two? when i try to git merge master, i get told "refusing to merge unrelated histories"
r/gitlab on Reddit: How am I supposed to merge these two? when I try to git merge master, I get told "refusing to merge unrelated histories"
March 11, 2022 - This is not an edge case and has nothing to do with the default branch being main instead of master. This has nothing to do with GitLab. This has everything to do with a person that doesn't understand how to use git. More replies · DeusPaul • · 4y ago · Try: git pull origin main --allow-unrelated-histories ·
🌐
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: git pull origin master --allow-unrelated-histories
🌐
Git Scripts
gitscripts.com › git-pull-allow-unrelated-histories
Git Pull Allow Unrelated Histories: A Quick Guide
October 10, 2025 - Another real-life scenario involves ... git remote add upstream https://github.com/originaluser/repo.git git pull upstream master --allow-unrelated-histories...
🌐
DEV Community
dev.to › abisaifredrick › fatal-refusing-to-merge-unrelated-histories-3bb4
fatal: refusing to merge unrelated histories - DEV Community
August 12, 2024 - git merge --allow-unrelated-histories <branch-name> When pulling, this flag can be used as follows: git <branch-name> origin master --allow-unrelated-histories · Create a new empty commit that connects unrelated branches then merge those branches.
🌐
LabEx
labex.io › tutorials › git-how-to-resolve-refusing-to-merge-unrelated-histories-error-in-git-417643
How to resolve 'refusing to merge unrelated histories' error in Git | LabEx
To resolve the "refusing to merge ... when merging the repositories. This option tells Git to proceed with the merge, even if the two repositories have completely different histories. git pull origin master --allow-unrelated-...
🌐
Tim Mousk
timmousk.com › blog › git-refusing-to-merge-unrelated-histories
How To Fix “fatal: refusing to merge unrelated histories” in Git? – Tim Mouskhelichvili
March 12, 2023 - To fix the "fatal: refusing to merge unrelated histories" error, toggle the allow unrelated histories option on the git pull command, like so: bashgit pull origin main --allow-unrelated-histories
🌐
GitHub
gist.github.com › kingluddite › 7ec82fdfa3700427efa0e5b97196dea6
unrelated-histories.md · GitHub
If you're certain that you want to merge the unrelated histories, you can force Git to do so with the --allow-unrelated-histories flag: git pull origin <branch-name> --allow-unrelated-histories