During git rebase origin/development
the following error message is shown from Git:
fatal: refusing to merge unrelated histories
Error redoing m
I had the same problem. Try this:
git pull origin master --allow-unrelated-histories
git push origin master
I ran this command and issue got resolved.1
git pull origin branchName --allow-unrelated-histories
I tried git pull --allow-unrelated-histories
didn't work, but what solves this issue for me was:
I copied all the files on my desktop repository to another folder and then deleted the folder.
Then I clone the repo again because it is a new project.
When I copied my files again and push it worked like charm.
This usually happens when you commit first time to remote repository. As error clearly says "refusing to merge unrelated histories", we need to use --allow-unrelated-histories flag.
git pull origin master --allow-unrelated-histories
Now there would be some conflicts which we have to solve manually. After that just commit the code and push it.
I see the most voted answer doesn't solve this question, which is in the context of rebasing.
The only way to synchronize the two diverged branches is to merge them back together, resulting in an extra merge commit and two sets of commits that contain the same changes (the original ones, and the ones from your rebased branch). Needless to say, this is a very confusing situation.
So, before you run git rebase
, always ask yourself, “Is anyone else looking at this branch?” If the answer is yes, take your hands off the keyboard and start thinking about a non-destructive way to make your changes (e.g., the git revert
command). Otherwise, you’re safe to re-write history as much as you like.
Reference: https://www.atlassian.com/git/tutorials/merging-vs-rebasing#the-golden-rule-of-rebasing
When doing a git pull
, I got this message fatal: refusing to merge unrelated histories
for a repo module where I hadn't updated the local copy for a while.
I ran this command just to refresh local from origin. I just wanted latest from remote and didn't need any local changes.
git reset --hard origin/master
This fixed it in my case.