Description

This control ensures that existing approvals on a pull request targeting the default branch are automatically dismissed when new commits are pushed to it. Reviewers must re-approve the pull request after any change before it can be merged.

Rationale

Without this setting, code can be added to a pull request after it has been approved and then merged without further review. Dismissing stale approvals ensures that every change merged into the default branch has been reviewed in its final form, preventing unreviewed or malicious code from being introduced after approval.

Impact

  • Reviewers must re-approve pull requests after new commits are pushed.

  • May increase review effort and time to merge for pull requests that change frequently.

  • Prevents unreviewed changes from being merged under a previous approval.

  • Supports change management and compliance requirements.

Default Value

  • Disabled by default. Repository administrators must explicitly enable this option in a ruleset or classic branch protection rule.

Remediation

Branch protection can be configured using rulesets, classic branch protection rules, or both. Complete the section that matches the repository’s configuration. The control is met if either configuration enforces the requirement.

Rulesets

Test Plan

  1. Sign in to GitHub with administrative access to the repository.

  2. Navigate to the target repository.

  3. Select Settings.

  4. Under Code and automation, select Rules → Rulesets.

  5. Verify that an active branch ruleset targets the default branch, that Require a pull request before merging is enabled, and that Dismiss stale pull request approvals when new commits are pushed is enabled.

  1. If no active ruleset targets the default branch or the setting is not enabled, follow the Implementation Steps below to remediate the issue and repeat the test.

Implementation Steps

  1. Sign in to GitHub with administrative access to the repository.

  2. Navigate to the target repository.

  3. Select Settings.

  4. Under Code and automation, select Rules → Rulesets.

  5. Click New ruleset and select New branch ruleset, or edit an existing branch ruleset.

  1. Enter a name for the ruleset.

  2. Under Enforcement status, select Active.

  3. Under Target branches, click Add target and select Include default branch.

  4. In the Rules section, enable Require a pull request before merging.

  5. Under the additional settings for this rule, enable Dismiss stale pull request approvals when new commits are pushed.

  1. Click Create (or Save changes for an existing ruleset) to apply the ruleset.

Backout Plan

  1. Sign in to GitHub with administrative access to the repository.

  2. Navigate to the target repository.

  3. Select Settings.

  4. Under Code and automation, select Rules → Rulesets.

  5. Edit the applicable branch ruleset.

  6. Disable Dismiss stale pull request approvals when new commits are pushed.

  7. Click Save changes.

Classic Branch Protection Rule

Test Plan

  1. Sign in to GitHub with administrative access to the repository.

  2. Navigate to the target repository.

  3. Select Settings.

  4. Under Code and automation, select Branches.

  5. Under Branch protection rules, verify that a rule matches the default branch (e.g., main).

  6. Click Edit next to the rule and verify that Require a pull request before merging and Dismiss stale pull request approvals when new commits are pushed are selected.

  1. If no matching rule exists or the setting is not selected, follow the Implementation Steps below to remediate the issue and repeat the test.

Implementation Steps

  1. Sign in to GitHub with administrative access to the repository.

  2. Navigate to the target repository.

  3. Select Settings.

  4. Under Code and automation, select Branches.

  5. Next to Branch protection rules, click Add classic branch protection rule, or click Edit next to an existing rule.

  1. In Branch name pattern, enter the name of the default branch (e.g., main).

  2. Select Require a pull request before merging.

  3. Select Dismiss stale pull request approvals when new commits are pushed.

  1. Click Create (or Save changes for an existing rule) to apply the rule.

Backout Plan

  1. Sign in to GitHub with administrative access to the repository.

  2. Navigate to the target repository.

  3. Select Settings.

  4. Under Code and automation, select Branches.

  5. Click Edit next to the applicable branch protection rule.

  6. Clear Dismiss stale pull request approvals when new commits are pushed.

  7. Click Save changes.

  8. Verify that approvals remain in place after new commits are pushed to a pull request.

References