Interview Prep/Git & GitHub/Protection, Hooks and Policy

An approved PR gets a new commit just before merge. How do you prevent unreviewed code from slipping in?

IntermediateScenarioProtection, Hooks and Policy
Answer

Situation read → An approval should apply to the code that was reviewed.

What I'd do →

  1. Enable "Dismiss stale pull request approvals when new commits are pushed".
  2. Enable "Require approval of the most recent reviewable push" so the pusher cannot self-approve.
  3. Require review from Code Owners for sensitive paths.

Why → Otherwise a malicious or careless push after approval merges unchecked.

Interview tip → This is a common supply-chain control question.

All Git & GitHub questions Roadmap: Git & GitHub

More on Protection, Hooks and Policy