Interactive Rebase from the Merge-Base
Interactive Rebase from the Merge-Base
Thesis
git rebase -i main rebases onto main’s tip. Sometimes you only want to edit commits unique to your branch since it forked — that set is merge-base(HEAD, main)..HEAD. Starting the todo from the merge-base keeps upstream commits out of your squash/reword list.
Mental model
o----o----o main
\
a----b----c feature
merge-base = o
rebase -i $(git merge-base HEAD main) → todo: a, b, c
Worked examples
Lab output:
main=40c708e feature=3541637
merge-base=6a07c0a
--- log feature ---
3541637 f3
bb6b435 f2
261afe9 f1
--- after: git rebase -i $(git merge-base HEAD main) would open todo for: ---
261afe9 f1
bb6b435 f2
3541637 f3
Trap
Confusing this with git rebase --onto. See 07-rebase-onto.qmd for --onto.
Boring rule
When cleaning a feature branch before review, open the interactive todo from the merge-base so you only see your commits.
Try this
- Add a conflicting upstream commit and finish the rebase.
- Compare
git rebase -i maintodo vs merge-base todo after main moves. - Use
git rebase -i --update-refswhen stacked branches exist.
Sources
git-merge-base(1),git-rebase(1)