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

You have a 60-commit branch full of experiments and need a reviewable PR.

IntermediateScenarioRebase, Cherry-pick and History Rewriting
Answer

Situation read → The final tree is good but the history is unreadable.

What I'd do →

  1. Keep a backup: git branch experiment-backup.
  2. git reset --soft $(git merge-base origin/main HEAD) collapses everything into staged changes.
  3. Re-commit in logical pieces using git add -p: schema, core logic, API, tests, docs.
  4. Force-push the cleaned branch.

Why → You build the story you want reviewers to follow, with tests passing at each step.

Interview tip → Alternatively, offer several smaller PRs. Reviewers handle those much better.

All Git & GitHub questions Roadmap: Git & GitHub

More on Rebase, Cherry-pick and History Rewriting