Interview Prep/Git & GitHub/Rebase, Cherry-pick and History Rewriting

You want to rebase a branch that contains merge commits without flattening them.

AdvancedScenarioRebase, Cherry-pick and History Rewriting
Answer

Situation read → Default rebase drops merge commits and linearises the commits.

What I'd do →

  1. git rebase --rebase-merges origin/main (-r) recreates the merge topology.
  2. Check the todo list: it shows label, reset, merge commands.
  3. Resolve conflicts inside the rebuilt merges as they appear.
  4. Compare afterwards: git range-diff origin/main@{1}...HEAD.

Why → --rebase-merges replaces the old --preserve-merges, which was removed because it handled interactive edits badly.

Interview tip → git range-diff shows what really changed between two versions of a rewritten branch.

All Git & GitHub questions Roadmap: Git & GitHub

More on Rebase, Cherry-pick and History Rewriting