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

Your PR branch has ten commits like "wip", "fix typo", "oops". How do you clean it up before review?

BeginnerScenarioRebase, Cherry-pick and History Rewriting
Answer

Situation read → Private, unreviewed history can be rewritten. Reviewers want a readable story.

What I'd do →

  1. git rebase -i origin/main.
  2. Keep the first meaningful commit as pick; change the noise commits to squash (merge messages) or fixup (discard messages).
  3. Rewrite the final messages in the editor.
  4. git push --force-with-lease.

Why → One logical commit per change makes review, bisect and revert simple.

Interview tip → Say you only rewrite commits nobody else has based work on.

All Git & GitHub questions Roadmap: Git & GitHub

More on Rebase, Cherry-pick and History Rewriting