git rebase --rebase-merges <branchname>

Rebase a branch incorporating merge commits.

This command rebases the current branch onto the specified branch, such as 'main', while preserving merge commits.

Unlike the default rebase which flattens the merge history, the --rebase-merges option keeps the topology of merge commits intact. This is particularly useful for maintaining a clear history of merges and their resolutions as if they were replayed on top of the new base.

Variants of this command include using --interactive (or -i) to manually select which commits to rebase, and including a shorter flag --rebase-merges=<mode> where <mode> could be 'rebase-cousins' or 'no-rebase-cousins', to control the behavior of rebasing branches that don't have the upstream as a direct ancestor.

Sign in to enable bookmarking, reminders, progress-tracking and more...