Description
Ensure a ruleset on the repository's default branch prevents that branch from being deleted.
Rationale
The default branch is typically the primary source of truth for the codebase and the target of CI/CD pipelines and deployments. Deleting it, whether by accident or through a compromised account, causes an immediate and severe availability impact.
Impact
Prevents accidental or malicious deletion of the repository's default branch
Protects the primary source of truth for the codebase and its history
Prevents CI/CD pipelines and deployments tied to the default branch from breaking unexpectedly
Reduces the impact of a compromised account with push access
Default Value
By default, a repository with no ruleset targeting its default branch has no restriction on deleting that branch; anyone with sufficient permissions can delete it.
Pre-Requisites
Admin access to the repository
Test Plan
Sign in to GitHub at https://github.com.
Select the relevant repository.
Click Settings.
In the "Code, planning, and automation" section of the sidebar, click Rulesets.
Select the ruleset that targets the default branch.
Verify that Restrict deletions is enabled.
If Restrict deletions is not enabled, or no ruleset targets the default branch, follow the implementation steps.
Implementation Steps
Sign in to GitHub at https://github.com.
Select the relevant repository.
Click Settings.
In the "Code, planning, and automation" section of the sidebar, click Rulesets.
Select the existing ruleset that targets the default branch, or click New ruleset, then New branch ruleset.
Under Ruleset Name, enter a name, and set Enforcement status to Active.
Under Target branches, click Add target, then select Include default branch.
Under Rules, enable Restrict deletions.
Click Create or Save changes.
Backout Plan
Sign in to GitHub at https://github.com.
Select the relevant repository.
Click Settings.
In the "Code, planning, and automation" section of the sidebar, click Rulesets.
Select the ruleset that targets the default branch.
Disable Restrict deletions.
Click Save changes.
Reference