Branch protection turns repository policy into enforceable controls. It reduces accidental direct pushes and makes the expected path to integration visible.
Define protected branches
Protect the primary integration branch and maintained release branches. Require pull requests, successful automated checks, and appropriate approvals. Decide whether administrators may bypass rules and how emergency changes are handled.
Require meaningful checks
A green check should represent a useful signal: tests, static analysis, dependency checks, formatting, or build verification. Avoid requiring flaky or irrelevant checks because teams will eventually seek ways around them.
Ensure the checks run against the exact commit that will be merged. Where supported, require the branch to be up to date or use merge queues.
Limit privileged access
Restrict who can modify protection rules, secrets, and repository settings. Review bot permissions and automation tokens. A workflow that can write to protected branches should have narrowly scoped credentials.
Checklist
- Protect primary and release branches.
- Require review and reliable status checks.
- Limit bypass and settings permissions.
- Scope automation credentials narrowly.
- Audit policy changes periodically.