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 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
19 hours 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....
Discussions

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
error "fatal: refusing to merge unrelated histories" when pulling from a repository?
Select Topic Area Question Body how do i fix this issue? More on github.com
🌐 github.com
1
1
git pull - Git is refusing to merge unrelated histories. What are 'unrelated histories'? - Stack Overflow
I created a local repo with git remote origin https:////.... Then, in that local repo, I made a new text file → git add newfile.txt → git commit -m "..." → git pull origin main → ERROR! &... 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
🌐
Educative
educative.io › answers › the-fatal-refusing-to-merge-unrelated-histories-git-error
The “fatal: refusing to merge unrelated histories” Git error
You have created a new repository, ... has no idea how the two projects are related. The error is resolved by toggling the allow-unrelated-histories switch....
🌐
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
🌐
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.
Find elsewhere
🌐
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:
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.

🌐
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.
🌐
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 - A more reliable way is to download the remote repository to the local machine using the git clone command, like this: ... This way, we copy the repository from the remote server, and the commit history base remains the same for both remote and local branches. In this tutorial, we discussed how to merge branches when Git is refusing to merge unrelated histories.
🌐
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 - The fatal: refusing to merge unrelated histories git error can be resolved using the --allow-unrelated-histories flag. On Career Karma, learn how to resolve this common error.
🌐
Mazer.dev
mazer.dev › en › git › troubleshooting › how-to-fix-git-fatal-error-refusing-to-merge-unrelated-histories
How to fix Git fatal error: refusing to merge unrelated histories - Mazer.dev
October 1, 2022 - To solve this error just use the option allow-unrelated-histories. To allow GIT to make the merge of two projects with different histories, pass the parameter --uslow-unreard-histories when making the pull, like this:
🌐
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:
🌐
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. ... Merging unrelated histories can result in a confusing commit graph.
🌐
Datree
datree.io › resources › git-error-fatal-refusing-to-merge-unrelated-histories
Fix Git Error - Fatal: refusing to merge unrelated histories - Datree.io | Datree.io
November 21, 2019 - In short, the solution is to use the flag --allow-unrelated-histories. If the error occurred while using $git pull then this is an example:
🌐
Namehero
namehero.com › blog › resolving-the-fatal-refusing-to-merge-unrelated-histories-error
Resolving the "Fatal: Refusing to Merge Unrelated Histories" Error
April 9, 2025 - In git, the “fatal: refusing to merge unrelated histories” error occurs when you merge two branches with no common ancestor and git doesn’t know where to begin the merge. This error doesn’t occur in the normal git workflow, but it can happen when you try to combine two unrelated git projects into a single one, or you’re trying to add some changes to a remote project for the first time without doing a pull.
🌐
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 - Now you are trying to pull from ... not know how the two projects are related. You can solve this issue by adding the allow-unrelated-histories flag....