git-fu

June 4, 2025

git is one of those tools that you learn once and you never have t—and then you learn twice, and then you learn thrice, and then you learn…

And then you write a blog post about it. So anyway, this is an overview of learnings using git over the years. They are mostly public notes for myself and I will try to keep this post updated whenever new things come up.

git rebase --onto

The command that prompted me to write this post originally.

Scenario:

How do you merge this? The normal stacked PR strategy would be:

However, what if the changes in feature-A have been reviewed and should land ASAP. If you merge feature-A into main, the feature-B will be orphaned, it will rely on commits that are no longer there (remember: we’re squash-merging).

This is where git rebase --onto is helpful. You need to make sure of two things:

Run:

git checkout feature-B # just to make sure we're here
git rebase --onto main feature-A

This command takes all commits from your current branch (feature-B) that aren’t in feature-A (i.e. that have been added on top of feature-A changes), and replays them on top of main.

< Back