How to rebase onto a different branch with git


Current Situation and how to move your branch

Just imagine the following situation: base

We have a feature-branch which we branched off from develop but we want to have the stuff on release.

So what we want is basically to move our commits from develop to release like this: intermediate

The fix is very easy with git:

$ git rebase --onto new-base-branch old-base-branch mybranch

That would mean in our example:

$ git rebase --onto release develop feature-branch

The target picture would look like that: target

Note If you are already working on feature-branch you can omit the third parameter.

How does it work?

The basic idea behind the rebase onto is

  1. Finding the common ancestor of the old and new base branch
  2. Reapplying your commits to new base branch

Finding the common ancestor between the old and new base branch

In the example we see that the orange commit is the common ancestor of release and develop branch step1

Reapplying your commits to new base branch

Now we just apply our commits from the feature-branch to the release branch




If you have some amount of commits and cherry-picking is to time consuming use the "magic" of git rebase --onto.

Buy Me a Coffee at
An error has occurred. This application may no longer respond until reloaded. Reload x