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

You must backport 15 commits to three old release branches. How do you make it repeatable?

AdvancedScenarioRebase, Cherry-pick and History Rewriting
Answer

Situation read → Doing 45 cherry-picks by hand is error-prone.

What I'd do →

  1. Collect the commits in order: git rev-list --reverse --no-merges <range> > picks.txt.
  2. Script it per branch:
for br in release/3.8 release/3.9 release/4.0; do
  git switch -c "backport-$br" "origin/$br"
  xargs -n1 git cherry-pick -x < picks.txt || break
  git push origin "backport-$br"
  gh pr create --base "$br" --fill
done
  1. Stop on the first conflict and fix by hand; let CI test each PR.
  2. Prefer a bot (GitHub Action with labels such as backport 4.0) for the long run.

Why → Oldest-first order matters, since later commits assume earlier ones.

Interview tip → Mention using PR labels to trigger automated backports.

All Git & GitHub questions Roadmap: Git & GitHub

More on Rebase, Cherry-pick and History Rewriting