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

You have stacked branches (A, B, C) and need to rebase the whole stack after A changes.

AdvancedScenarioRebase, Cherry-pick and History Rewriting
Answer

Situation read → Rebasing only the top branch leaves A and B pointing at old commits.

What I'd do →

  1. Check out the top branch C.
  2. git rebase -i --update-refs origin/main (Git 2.38+); the todo list updates A and B pointers too.
  3. Push all: git push --force-with-lease origin A B C.
  4. Or use tooling such as gh stack-style helpers, Graphite or ghstack for larger stacks.

Why → --update-refs moves every branch whose tip is inside the rebased range.

Interview tip → Stacks keep PRs small but need discipline: merge bottom-up and retarget as you go.

All Git & GitHub questions Roadmap: Git & GitHub

More on Rebase, Cherry-pick and History Rewriting