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

You rebased and force-pushed a branch your teammate also had checked out. What does he do now?

AdvancedScenarioRebase, Cherry-pick and History Rewriting
Answer

Situation read → His local branch has the old commits, the remote has new ones. A normal git pull will merge both and duplicate commits.

What I'd do →

  1. If he has no local commits: git fetch && git reset --hard origin/feature.
  2. If he has local commits: git rebase --onto origin/feature <old-remote-tip> feature, where the old tip comes from git reflog show origin/feature.
  3. Or git pull --rebase, which uses the fork-point to drop the duplicates automatically.

Why → Git needs to know which of his commits are already rewritten upstream. Fork-point detection uses the reflog.

Interview tip → Better still: announce before rewriting shared branches, or avoid doing it.

All Git & GitHub questions Roadmap: Git & GitHub

More on Rebase, Cherry-pick and History Rewriting