How does GitHub's 'Require branches to be up to date before merging' protection work?
Select an answer to reveal the explanation.
Short Explanation and Infographic
The 'up to date' branch requirement prevents merging a PR that's diverged from main. If main has moved on since your branch was created, you must bring your branch current before merging — ensuring you've tested against the latest codebase.
Full explanation below image
Full Explanation
The 'Require branches to be up to date before merging' branch protection setting (part of required status checks configuration) prevents merging a pull request if the head branch is behind the base branch. When this setting is enabled: (1) If new commits have been pushed to the base branch (e.g., main) after the PR branch was created or last updated, the merge button is disabled. (2) The PR author must update their branch (via merge or rebase) to include the latest base branch changes. (3) After updating, CI must re-run and pass on the combined code. (4) Only then can the PR be merged. This prevents 'passing in isolation but failing after merge' scenarios by ensuring PRs always have the latest changes incorporated before merge.