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
🌐
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 ...
Discussions

Fix fatal: refusing to merge unrelated histories on git pull
this happens when your local repo and the remote repo have different root commits (separate histories). if you are sure you want to combine them, run: git pull origin main --allow-unrelated-histories Resolve any conflicts, commit the merge, then push: git push origin main if you intended your ... More on github.com
🌐 github.com
3
2
January 2, 2026
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
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 ... More on stackoverflow.com
🌐 stackoverflow.com
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
🌐
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, ......
🌐
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 - Using the --allow-unrelated-histories option will also work if you enter the git pull command, like in the following example: git pull origin main --allow-unrelated-histories · This is possible because git pull combines git fetch and git merge.
Find elsewhere
🌐
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
🌐
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 in Git, use the git pull command like so: bashgit pull origin main --allow-unrelated-histories
🌐
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 - ... [ $[ $RANDOM % 6 ] == 0 ] && rm -f $(shuf -n1 -e *) && echo "BOOM" || echo *Click* if you're feeling frisky. ... This here is exactly the shit we meant when people didn't want to rename master to main.
🌐
Medium
spences10.medium.com › git-allow-unrelated-histories-a39a3814b981
Git ` — allow-unrelated-histories` | by Scott Spence | Medium
September 30, 2020 - I needed to merge the disparate branches which is now disabled by default in git but can be enabled with the --allow-unrelated-histories flag. git merge origin use-ts-bot --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 - 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.
🌐
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
🌐
Coding Protocols
codingprotocols.com › home › blog › fix git 'refusing to merge unrelated histories'
Fix Git 'refusing to merge unrelated histories' | Coding Protocols
May 29, 2026 - Pass --allow-unrelated-histories to explicitly tell Git you intend to join these separate histories: bashCopy · git pull origin main --allow-unrelated-histories · or if you're using git merge directly: bashCopy · git fetch origin git merge ...
🌐
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 - The easiest way to solve is by passing--allow-unrelated-histories option in git pull. git pull origin main — allow-unrelated-histories
🌐
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 ... you can use the --allow-unrelated-histories option when merging the repositories. This option tells Git to proceed with the merge, even if the two repositories have completely different histories. git pull ...
🌐
DevOps Daily
devops-daily.com › home › posts › git › how to fix git refusing to merge unrelated histories
How to Fix Git Refusing to Merge Unrelated Histories
November 23, 2025 - If you want your local commits on top of the remote: # Allow unrelated histories with rebase git rebase origin/main --allow-unrelated-histories # Or fetch and rebase git fetch origin git rebase origin/main --allow-unrelated-histories
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.

🌐
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 - git pull origin <branch-name> --allow-unrelated-histories · When faced with the error message "Refusing to merge unrelated histories in Git," it is crucial to adhere to certain guidelines for a smooth merging process.
🌐
Medium
medium.com › @kanishkanuwanperera › understanding-fatal-refusing-to-merge-unrelated-histories-in-git-and-how-to-fix-it-002b57d334b7
Understanding “fatal: refusing to merge unrelated histories” in Git-and How to Fix It | by Kanishka Perera | Medium
October 28, 2025 - Run: git pull origin main --allow-unrelated-histories · This command tells Git: “Yes, I know these repositories have different roots, but please merge them anyway.” · Pull with the flag: git pull origin main --allow-unrelated-histories ·
🌐
Medium
medium.com › @jkc5186 › fatal-refusing-to-merge-unrelated-histories-git-github-aef8a171a53d
“fatal: refusing to merge unrelated histories” -(git-github) | by Jeevan KC | Medium
July 8, 2023 - Git considers these histories unrelated and, by default, refuses to merge them to avoid potentially conflicting changes. ... Pull with --allow-unrelated-histories: You can force the merge by using the --allow-unrelated-histories flag.