Description
This control ensures that force pushes are blocked on the repository’s default branch. A force push overwrites the remote branch history and can remove or alter previously committed changes.
Rationale
Force pushes can rewrite or erase commit history, removing reviewed code, approved changes, or evidence of past changes. Blocking force pushes on the default branch preserves the integrity and auditability of the branch history and prevents accidental or malicious loss of code.
Impact
Users cannot rewrite or overwrite the history of the default branch using force pushes.
Mistaken commits must be reverted with new commits instead of being removed from history.
Preserves a complete and reliable audit trail of changes.
Supports change management and compliance requirements.
Default Value
Force pushes are not blocked on branches without protection. Repository administrators must configure a ruleset or classic branch protection rule that blocks force pushes.
Remediation
Branch protection can be configured using organization rulesets, repository rulesets, classic branch protection rules, or a combination of these. Organization rulesets apply one configuration to many repositories at once (GitHub Team or Enterprise plan required). Complete the section that matches the repository’s configuration. The control is met if any of these configurations enforces the requirement.
Organization Rulesets
Test Plan
Sign in to GitHub as an organization owner or a user with the Manage organization ref update rules and rulesets permission.
Click your profile picture in the upper-right corner, select Organizations, and select the target organization.
Select Settings.
Under Code, planning, and automation, select Repository → Rulesets.
Verify that an active branch ruleset targets the in-scope repositories (Target repositories) and the default branch (Target branches), and that Block force pushes is enabled.
Review the Bypass list and confirm that only approved users, teams, or apps can bypass the ruleset.
If no active organization ruleset targets the in-scope repositories and the default branch, or Block force pushes is not enabled, follow the Implementation Steps below to remediate the issue and repeat the test.
Implementation Steps
Sign in to GitHub as an organization owner or a user with the Manage organization ref update rules and rulesets permission.
Click your profile picture in the upper-right corner, select Organizations, and select the target organization.
Select Settings.
Under Code, planning, and automation, select Repository → Rulesets.
Click New ruleset and select New branch ruleset, or edit an existing branch ruleset.
Enter a name for the ruleset.
Under Enforcement status, select Active.
Under Target repositories, select the repositories to protect (all repositories, repositories matching a name pattern, repositories with a custom property, or a selected list).
Under Target branches, click Add target and select Include default branch.
In the Rules section, enable Block force pushes.
Click Create (or Save changes for an existing ruleset) to apply the ruleset.
Backout Plan
Sign in to GitHub as an organization owner or a user with the Manage organization ref update rules and rulesets permission.
Click your profile picture in the upper-right corner, select Organizations, and select the target organization.
Select Settings.
Under Code, planning, and automation, select Repository → Rulesets.
Edit the applicable branch ruleset.
Disable Block force pushes, or remove the affected repositories from Target repositories.
Click Save changes.
Repository Rulesets
Test Plan
Sign in to GitHub with administrative access to the repository.
Navigate to the target repository.
Select Settings.
Under Code and automation, select Rules → Rulesets.
Verify that an active branch ruleset targets the default branch and that Block force pushes is enabled.
If no active ruleset targets the default branch or Block force pushes is not enabled, follow the Implementation Steps below to remediate the issue and repeat the test.
Implementation Steps
Sign in to GitHub with administrative access to the repository.
Navigate to the target repository.
Select Settings.
Under Code and automation, select Rules → Rulesets.
Click New ruleset and select New branch ruleset, or edit an existing branch ruleset.
Enter a name for the ruleset.
Under Enforcement status, select Active.
Under Target branches, click Add target and select Include default branch.
In the Rules section, enable Block force pushes.
Click Create (or Save changes for an existing ruleset) to apply the ruleset.
Backout Plan
Sign in to GitHub with administrative access to the repository.
Navigate to the target repository.
Select Settings.
Under Code and automation, select Rules → Rulesets.
Edit the applicable branch ruleset.
Disable Block force pushes.
Click Save changes.
Verify that force pushes are permitted according to the updated configuration.
Classic Branch Protection Rule
Test Plan
Sign in to GitHub with administrative access to the repository.
Navigate to the target repository.
Select Settings.
Under Code and automation, select Branches.
Under Branch protection rules, verify that a rule matches the default branch (e.g., main).
Click Edit next to the rule and verify that Allow force pushes is cleared.
If no matching rule exists or Allow force pushes is selected, follow the Implementation Steps below to remediate the issue and repeat the test.
Implementation Steps
Sign in to GitHub with administrative access to the repository.
Navigate to the target repository.
Select Settings.
Under Code and automation, select Branches.
Next to Branch protection rules, click Add classic branch protection rule, or click Edit next to an existing rule.
In Branch name pattern, enter the name of the default branch (e.g., main).
Under Rules applied to everyone including administrators, ensure Allow force pushes is cleared.
Click Create (or Save changes for an existing rule) to apply the rule.
Backout Plan
Sign in to GitHub with administrative access to the repository.
Navigate to the target repository.
Select Settings.
Under Code and automation, select Branches.
Click Edit next to the applicable branch protection rule.
Under Rules applied to everyone including administrators, select Allow force pushes and choose who can force push.
Click Save changes.
Verify that force pushes are permitted according to the updated configuration.