How to rebase onto a different branch with git

17/08/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!

How to hunt down bugs with git bisect

This article will show how you can identify the commit a bug was introduced.

Sometimes it is hard to track down a bug. Your only chance is to exploratory test your code until you find the code in question. I will show you a way how to do this with git. More specific how to use git bisect

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