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

You committed to `feature-a` but the commit belongs on `feature-b`, and `feature-a` has other commits after it.

IntermediateScenarioRebase, Cherry-pick and History Rewriting
Answer

Situation read → One commit is in the wrong place in the middle of unpushed history.

What I'd do →

  1. git switch feature-b && git cherry-pick <sha>.
  2. Back on feature-a: git rebase -i <sha>^ and drop the commit.
  3. Resolve conflicts if later commits relied on it.

Why → Cherry-pick copies it to the right branch, and rebase removes the original.

Interview tip → If the branches are pushed and shared, revert instead of dropping.

All Git & GitHub questions Roadmap: Git & GitHub

More on Rebase, Cherry-pick and History Rewriting