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):
- make sure you have a clean working tree (no uncommit changes)
- checkout to the branch you want to rebase onto (for instance, let's say it's
master
; as a one-line command): git checkout master && git pull origin master && git checkout development
- Do the actual rebase:
git rebase master
- If it's done and everything works as expected, push it to your remote. For doing so, you need to force it, because the remote host already has the history in another order, the remote would answer with nothing to push. So, we need to say "my local version of the history is correct, overwrite everything on that remote branch using my local version of the history":
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.
git-rebase
situation while the answer gives a flag forgit-merge
– Shubham Chaudharygit pull [repo URL]
instead ofgit clone [repo URL]
– rsoren