Fix - "fatal:refusing to merge unrelated histories" git error
This article is about how to resolve or fix fatal:refusing to merge unrelated histories git error.
This article is about how to resolve "fatal:refusing to merge unrelated histories" in git error.
This error occurs when we try to merge two completely unrelated git repositories together into one.
Before git 2.9, git merge allowed the merge of two different repositories with unrelated histories, but its used to cause lots of errors when done by mistake.
However with the update of git 2.9, it is not allowed by default, now we have to add a flag to specify the unrelated merge.
Cause of the merge error
- When you have a local repository and you try to push your changes on a newly created repository in GitHub.
- When your
.gitfolder is corrupted or deleted by mistake. And this makes the local change histories unrelated. And we get the error when we try to pull or merge our changes to and from a remote repository.
Fix for fatal: unrelated histories error in git
To resolve the refusing to merge error, we have to allow the merge of the unrelated repository manually with the following tag --allow-unrelated-histories after the git pull or git merge command.
git pull origin master --allow-unrelated-histories
or for merge,
git merge --allow-unrelated-histories mybranchname
NOTE : make sure you do not use --allow-unrelated-histories flag unless you are sure about it. This check is use to prevent disaster when we merge unrelated repository.
Related Topics:
Related Posts
Fix 'failed to push some refs to' Git Errors
If you have encountered the "error: failed to push refs to" error in git, then follow this solution provided in this article to easily fix the error.
[Fixed] GitHub "fatal: remote origin already exists" error
Find out to fix "fatal: remote origin already exits" github error while working with remote git repository.
Solved "No such remote origin" Git Error Fatal
Short article on how do I fix remote origin already exists git error faced when trying to push to remote origin in Github and BitBucket.
How to remove node_modules from github or bitbucket
Step by step process to remove node_modules from github or bitbucket after the folder is added to the repository with the help of gitignore file.
