Branch protection is a feature in version control software that allows teams to define rules and restrictions around who can make changes to specific branches, what types of changes are allowed, and if there are conditions that have to be met.
This can include:
Number of reviewers
Linked work items e.g. PBIs (super useful to track back to why the code was changed)
Any feedback has been addressed/resolved
Enforcing specific merge types
Checking that builds pass
Checking other services e.g. code quality like SonarQube
Automatically adding specific people to review the code
❌ Figure: Bad example - No protection – anyone can make unreviewed changes
✅ Figure: Good example - The branch protected
A green build or approval on an earlier revision does not prove the latest change is ready. Configure branch protection so checks and human review cover the changes being merged.
For example, in GitHub:
Require a fresh human review - Require pull request reviews, and enable Dismiss stale pull request approvals when new commits are pushed and Require approval of the most recent reviewable push. Also require conversation resolution. Together, these make sure an authorised human approves the current changes.
Prevent bypasses - Apply protections to administrators and exclude agent identities from bypass access. An agent's review does not replace the required human approval.
Test against the latest base - Enable Require branches to be up to date before merging or Require merge queue. A queue tests the latest base with the PR and entries ahead of it. Required GitHub Actions workflows must also run on merge_group events.
Verify what ran - Require status checks before merging. Check results for the revision GitHub evaluates: the PR head, test-merge commit or queue integration commit. These can have different checks. Pending, skipped or neutral results do not prove that the intended tests ran and passed.
See GitHub's branch protection settings and merge queue configuration.
Where repository policy permits auto-merge, complete these checks before enabling it. Before pushing another change, disable auto-merge or remove the PR from the queue, then repeat checks and review. Treat a queued PR whose integration checks are still pending as waiting, not merged, until the platform confirms the merge.