How to rebase onto a different branch with git

8/17/2021

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

step2

step3

Conclusion

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

Branch Prediction - How much does an if cost?

In the blog post we will look a bit into branch prediction. What is it and how can it impact our code?

To explore this we will be Thomas the Signalman, which works at a very busy railroad.

How does git work?

In this blog post I will show you how git works. Or better we will see how git works on the example of some of the commands.

Are you confused about origin, remote, rebase or merge? You see stuff like origin/main and origin main and just question marks appear? Say no more!

Git Tricks: Get the last checked out branch

In this blog post I will show you two tricks how to easily switch between a branch back and forth and how to get the last checked out branches.

An error has occurred. This application may no longer respond until reloaded. Reload x