At OpenProject, we're using a main development branch dev as well as one or more longer running release tracking branches release/X.Y. When bugfixing, I will quite often want to backport a branch from the main development branch to a release branch.

With git rebase --onto, you can select the comitts from that bugfix branch without rebasing all the commits from dev. With lazygit v0.40, you can now select the base from within the commits panel.

Series index

Example: A bugfix backport

In our example, we have a released version v13.0.0 based on the release tracking branch release/13.0. The main branch is continuing with feature development. A bugfix branch is created against main.

gitGraph TB:
   commit id: "Released feature"
   branch release/13.0 order: 3
   checkout release/13.0
   commit id: "Release 13.0.0" tag: "v13.0.0"
   commit id: "Bugfix A"
   checkout main
   commit id: "Feature"
   branch Bugfix order: 2
   checkout Bugfix
   commit id: "Bugfix"
   commit id: "Writing regression test"

Now you want to rebase bugfix onto release/13.0. You try to remember the order of the rebase --onto command. I've bookmarked this following stackoverflow comment to remind me:

1
git rebase —onto <place-to-put-it>  <last-change-that-should-NOT-move> <change to move>

With lazygit v0.40, we can now do the same from within the commits panel. Here's how.

With the bugfix branch active, head to the commits panel

panels before rebase

Navigate to the first commit you do not want to move/backport and press Shift+b to select commits above it

This will result in the two bugfix commits (Bugfix and Writing regression test)

Two commits selected for rebasing

In the branches panel, select release/13.0 and press r. The rebase dialog will pop up to select simple or interactive rebasing. It informs you that rebasing happens from the marked base.

You can then continue with either rebase option, and the two commits will be rebased.

Two commits rebased onto release brnach