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

You accidentally merged `main` into your feature branch three times and want a linear branch again.

IntermediateScenarioRebase, Cherry-pick and History Rewriting
Answer

Situation read → Merge commits are cluttering a branch that should be a clean series.

What I'd do →

  1. git fetch origin.
  2. git rebase origin/main (without -r) drops the merges and replays only your own commits.
  3. Resolve conflicts once per commit.
  4. git push --force-with-lease.

Why → Default rebase ignores merge commits and picks the non-merge commits in the range.

Interview tip → If a merge itself had hand-resolved conflicts, check the final diff carefully, since that resolution may be lost.

All Git & GitHub questions Roadmap: Git & GitHub

More on Rebase, Cherry-pick and History Rewriting