Ensure branches are deleted automatically after merging

Framework Reference: A.8.9 (Configuration Management) Integration: GitHub – Repository Settings

Why this matters

Automatically deleting branches after merging helps maintain repository hygiene and reduces the attack surface for stale or abandoned branches.
Old branches can contain outdated code, unpatched vulnerabilities, or unreviewed changes that may later be reused incorrectly.

Enabling automatic branch deletion ensures that:

  • Merged feature branches are removed immediately after integration
  • The repository stays organized and easier to maintain
  • The risk of reintroducing outdated or insecure code is minimized

Without this control, repositories can accumulate hundreds of inactive branches that make audits and code reviews harder to manage.


What this check does

This check verifies that the repository setting “Automatically delete head branches” is enabled.
When active, GitHub deletes the source branch automatically after its pull request has been merged into the base branch.


How to fix it

From the GitHub Web Console

  1. Go to your repository on GitHub.
  2. Navigate to Settings → General.
  3. Scroll down to the Merge button section.
  4. Under Automatically delete head branches, check Automatically delete head branches after pull requests are merged.
  5. Click Save changes if required.

After this is enabled, GitHub will automatically remove merged branches, keeping the repository clean and secure.


Exceptions

  • The setting applies only to branches deleted after a pull request merge. Manually merged or unmerged branches are not affected.
  • Users with write access can still recreate deleted branches if necessary.
  • This setting must be configured per repository (it is not organization-wide by default).

Further Resources

Was this article helpful?