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
git pull - Git is refusing to merge unrelated histories. What are 'unrelated histories'? - Stack Overflow
The unrelated histories could tell in the above situation. I ended up removing and renamed the old repository in remote and it was solved. ... Save this answer. ... Show activity on this post. When Pull and Merge the Changes from the Remote Refuses Try Force Push ... If the above step results in the "fatal... More on stackoverflow.com
🌐 stackoverflow.com
"refusing to merge unrelated histories" with initial repository
Expected behaviour: some guidance ... two histories, favouring the remote repository ... - The command `git -c credential.helper= pull --progress origin` exited with an unexpected code: 128. The caller should either handle this error, or expect that exit code. (anonymous) @ core.ts:145 - core.ts:151 fatal: refusing to merge unrelated histories ... More on github.com
🌐 github.com
10
May 16, 2017
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
People also ask

How to Fix "fatal: refusing to merge unrelated histories" in Git
This error appears when you try to merge two Git repositories that share no common ancestor — their histories are completely unrelated from Git's perspective. A common trigger is creating a new repository on GitHub with an auto-generated README or LICENSE file and then trying to push a separate, pre-existing local repository to it. To resolve it, run git pull origin main --allow-unrelated-histories, which tells Git to proceed with the merge despite the lack of a shared ancestor. Git will then attempt to combine the two histories, potentially surfacing conflicts if both sides contain files with
🌐
git-tower.com
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 ...
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 - # You had a local clone cd existing-local-clone # Someone deleted and recreated the remote repo git pull # fatal: refusing to merge unrelated histories # The new remote has completely new commits
🌐
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
1 day 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....
🌐
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. This approach links their histories, helping to prevent the issue of unrelated histories.
Find elsewhere
🌐
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 - Ensure the branches you’re merging or rebasing are related to your project. The “fatal: refusing to merge unrelated histories” error happens when you try to merge or rebase branches that have no common commit history.
🌐
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 a git option --allow-unrelated-histories
🌐
YouTube
youtube.com › littles law
fatal: refusing to merge unrelated histories #git #gitissue #gitfix | Littles Law - YouTube
AboutPressCopyrightContact usCreatorsAdvertiseDevelopersTermsPrivacyPolicy & SafetyHow YouTube worksTest new features · © 2024 Google LLC
Published   July 31, 2023
Views   1K
🌐
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 - How to fix “fatal: refusing to merge unrelated histories” in git Recently, I had to create a new GitHub repository to host GitHub App token generator Actions, but I had to delete it and to …
🌐
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 - The alternative (and longer) way of fixing the fatal: refusing to merge unrelated histories issues is to unstage your current commits, stash them, clone your required remote repository, and then place your stashed branch contents into the new clone.
🌐
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"
Use the --allow-unrelated-histories flag when merging their branches. ... If you have a new local repository and want to pull changes from an existing remote repository, use the --allow-unrelated-histories flag during the pull operation: ... ...
🌐
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).
🌐
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
To resolve this issue, you can pass the --allow-unrelated-histories option to the git merge or git rebase command. Here's how you can do it: ... Replace <branch-name> with the name of the branch you want to merge.
Top answer
1 of 7
300

I think you have committed in the remote repository, and when you pull, this error happens.

Use this command:

git pull origin main --allow-unrelated-histories
git merge origin origin/main
2 of 7
65

I ran into a similar problem where I brought in a branch from a second remote and wanted to merge with a branch from the first remote. This is different from the existing answers as I'm not using --allow-unrelated-histories on the pull, but on the merge.

git fetch origin main
git checkout main
git merge --allow-unrelated-histories myfunnybranch

This fetches and checks out the main branch and merges the myfunnybranch into it. By using git fetch rather than git pull we distinguish between bringing code to our machine, and performing the difficult merge.

When NOT to perform an unrelated history merge

Warning: An "unrelated history" is a history that does not go back to a common source. In other words, myfunnybranch and main are derived from two completely different repositories.

If the two repositories are very similar or have lots of files in common, there is a good chance that one of the repos lost its history somewhere along the way. Whether or not this is the case, its probably best to avoid two histories leading to the same set of files. Instead, you'd like to keep the longer history and have a single commit bringing in any changes from the other repository. To achieve this goal, checkout the repository with the longer history and copy the files of the other one in, which should produce a small commit with few changes, which git status and git diff will summarize for you before you make the commit with git commit. For more details, this answer to another question, which was mentioned in a comment on another answer to this question.

In the OP's case (which was elaborated on in an edit to the question), there is likely no need for an unrelated merge. Perhaps the OP didn't clone the repo, or perhaps someone else pushed to the empty repo before the OP made their initial commit. Either way, since the OP is editing only a single file, it would be better to simply clone the repo fresh, copy the new file into the cloned repo, and add, commit, and push there.

When TO perform an unrelated history merge

You would only want to merge unrelated histories if the two repositories indeed share very little in common. For example, each repository contributes a different set of files during the merges.

In my case I wanted to merge two totally different repos that had files in different directories and I wanted to preserve the history of both of these. This was code that I thought should be together in a single repo but was originally written in two different repos.

While the OP appears to be adding a new file here, this is probably not a case where we need multiple histories.

As P. Ent notes in a comment, one case where it makes sense to merge unrelated histories is when you have performed a fair bit of development locally, and there really hasn't been much development on origin/main. If essentially all of the development was done locally on myfunnybranch, it might even make sense to run

git checkout myfunnybranch
git merge -s ours --allow-unrelated-histories main

This ignores all the work on the main branch, but keeps it in the history. Only the code in myfunnybranch is kept. Now merging myfunnybranch back into main should be easy.

In cases like these, git log --all --graph is useful to see what your local repository looks like before you push anything.

For example, after the git merge -s ours command suggested above, you might find your repo to look like

git log --all --oneline --graph
*   6c8188b (HEAD -> myfunnybranch) Merge branch 'main' into myfunnybranch
|\
| * b93aabd (origin/main, origin/HEAD, main) Initial commit on remote server
* f69e99b some work I did locally
* df5d8ae more local work
* da455d6 Initial commit that I made locally

In this case you could use

git diff 6c8188b f69e99b 

to confirm that your most recent commit, 6c8188b, really didn't change any of the work you did locally. It will print nothing if there are no changes.

Then, merging myfunnybranch back into main will result in main matching your local development, too. This is because from the main branch's perspective, commit 6c8188b makes a whole bunch of edits bringing the branch exactly in line with the other branch.

🌐
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.
🌐
Junian
junian.net › dev › git-refusing-to-merge-unrelated-histories
How to Fix Git Refusing to Merge Unrelated Histories Issue
February 3, 2026 - Luckily, this is easy to fix. You just need to add the --allow-unrelated-histories option to your merge command. ... By default, the git merge command refuses to merge histories that do not share a common ancestor.
🌐
Frontendor
frontendor.com › blog › fatal-refusing-to-merge-unrelated-histories
"The Fatal: Refusing To Merge Unrelated Histories" Git Error
Git's "fatal": refusal to combine unrelated histories "error occurs when two unrelated projects are merged (i.e., projects that do not know each other and have a different commit history).
🌐
GitHub
github.com › desktop › desktop › issues › 1484
"refusing to merge unrelated histories" with initial repository · Issue #1484 · desktop/desktop
May 16, 2017 - Expected behaviour: some guidance about resolving these two histories, favouring the remote repository ... - The command `git -c credential.helper= pull --progress origin` exited with an unexpected code: 128. The caller should either handle this error, or expect that exit code. (anonymous) @ core.ts:145 - core.ts:151 fatal: refusing to merge unrelated histories (anonymous) @ core.ts:151
Author   desktop