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

Branch B was built on top of branch A. A was squash-merged into `main`, and now B shows A's commits again.

IntermediateScenarioRebase, Cherry-pick and History Rewriting
Answer

Situation read → The squash commit has new content ancestry, so Git cannot tell A's old commits are already in main.

What I'd do →

  1. Note A's last commit: git log --oneline A.
  2. Replay only B's own commits:
git fetch origin
git rebase --onto origin/main <A-tip-sha> B
git push --force-with-lease
  1. The PR now contains only B's changes.

Why → --onto takes the range A-tip..B and replants it on main.

Interview tip → This is the daily pain of stacked branches with squash merging.

All Git & GitHub questions Roadmap: Git & GitHub

More on Rebase, Cherry-pick and History Rewriting