During git rebase origin/development
the following error message is shown from git:
fatal: refusing to merge unrelated histories
Error redoing merge 1234deadbeef1234deadbeef
My git version is 2.9.0. Used to work fine in previous version.
How can I continue this rebase allowing unrelated histories with the forced flag introduced in the new release?
The 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.
You can use --allow-unrelated-histories
to force the merge to happen.
In my case, error was just fatal: refusing to merge unrelated histories
on every especially first pull request after remotely adding a git repo.
Using --allow-unrelated-histories
flag worked with pull request in this way:
git pull origin branchname --allow-unrelated-histories
Try the following command
git pull origin master --allow-unrelated-histories
this should solve your problem.
I got this error when I set up a local repository first. Then went to github and created a new repository. Then I ran
git remote add origin <repository url>
When I tried to push/pull, I got the same fatal: unrelated_histories
error.
Here is how I fixed it:
git pull origin master --allow-unrelated-histories
git merge origin origin/master
... add and commit here...
git push origin master
I had same problem. Try this:
git pull origin master --allow-unrelated-histories
git push origin master
Try git pull --rebase development
Since all the other answers are not actually answering the question, here is a solution inspired by this answer on a related question.
So you get your error doing git rebase:
$ git rebase origin/development
fatal: refusing to merge unrelated histories
Error redoing merge 1234deadbeef1234deadbeef
This error doesn\'t actually cancel the rebase, but you are now in the middle of it:
$ git status
interactive rebase in progress; onto 4321beefdead
Last command done (1 command done):
pick 1234deadbeef1234deadbeef test merge commit
So you can now do the merge by hand. Find out the parent commits of the original merge commit:
$ git log -1 1234deadbeef1234deadbeef
commit 1234deadbeef1234deadbeef
Merge: 111111111 222222222
Author: Hans Dampf
Date: Wed Jun 6 18:04:35 2018 +0200
test merge commit
Find out which of the two merge parents is the one that was merged into the current one (probably the second one, verify with git log 222222222
), and then do the merge by hand, copying the commit message of the original merge commit:
$ git merge --allow-unrelated 222222222 --no-commit
Automatic merge went well; stopped before committing as requested
$ git commit -C 1234deadbeef1234deadbeef
[detached HEAD 909af09ec] test merge commit
Date: Wed Jun 6 18:04:35 2018 +0200
$ git rebase --continue
Successfully rebased and updated refs/heads/test-branch.
I struggled with this as well but managed to find a workaround.
When you run into the error above just cherry-pick the merge commit and then continue the rebase:
git cherry-pick -m 1 1234deadbeef1234deadbeef
git rebase --continue
For this, enter the command as:-
git pull origin branchname --allow-unrelated-histories
Ex:- git pull origin master --allow-unrelated-histories
Reference:- Github unrelated histories issue