During git rebase origin/development
the following error message is shown from Git:
fatal: refusing to merge unrelated histories
Error redoing m
I struggled with this as well, but I 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
Try git pull --rebase development
Two possibilities when this can happen -
You have cloned a project and, somehow, the .git directory got deleted or corrupted. This leads Git to be unaware of your local history and will, therefore, cause it to throw this error when you try to push to or pull from the remote repository.
You have created a new repository, added a few commits to it, and now you are trying to pull from a remote repository that already has some commits of its own. Git will also throw the error in this case, since it has no idea how the two projects are related.
SOLUTION
git pull origin master --allow-unrelated-histories
Ref - https://www.educative.io/edpresso/the-fatal-refusing-to-merge-unrelated-histories-git-error
I just did a
git pull --allow-unrelated-histories
git pull origin <branch> --allow-unrelated-histories
You will be routed to a Vim edit window:
git push --set-upstream origin <branch>
I am using the rebase for years and I had never encountered such a problem. However, your first problem is, that you try to do it directly on the remote branch development
from the remote repository, called origin
. That is literally wrong because rebase is a dangerous command, that restructures the git history. Having said that, you should first try on your local repository and pushing it only, if it works for you as expected.
So, my usual rebase workflow looks like following (but please keep in mind, that you should not use rebase on branches, which you are not the only one committee. For such branches, use simply merge and resolve conflicts, if applicable):
master
; as a one-line command): git checkout master && git pull origin master && git checkout development
git rebase master
git push -f origin development
As I already mentioned, keep in mind, that rebase manipulates the git history, that is usually a bad thing. However, it's possible to do that on branches, where no one else commits to. In order to keep the branch pull-able for the other developers, use another merge strategy like merge itself, squash or cherrypick. So, in other words: Rebase shouldn't be your tool on distributed development. It works fine for you if you are the only one who works on this repository.
We use the feature branch strategy. In this, I usually use rebase in order to get the "updates" from the other developers, that happened in the meantime on the master branch. Doing so, it reduces the size of commits that are visible in a pull request. Therefore, it makes it easier for the code reviewer to see my changes made in this feature branch.