Branch protection is a setting on the repository host that decides what must be true before a change reaches a branch. It is the technical backstop for the rule that nothing unchecked is done.
Settings worth turning on for main
- Require a pull request before merging, so no one pushes straight to main.
- Require status checks to pass, and list the checks by name: tests, lint, typecheck.
- Require review from a person, with at least one approval.
- Dismiss stale approvals when new commits are pushed.
- Require branches to be up to date so checks ran on what will be merged.
- Block force pushes and deletion of the branch.
- Apply the rules to administrators, so they are not skipped under pressure.
Why it matters with agents
An agent with a token that can push to main can bypass review by accident. A protected branch makes the safe path the only path, whatever the agent was told.
Use a limited token
Give the agent’s credentials only the rights it needs, normally to push to its own branch and open a pull request.
Together with Contextingo
Contextingo fetches the CI results for the commit itself, and a maintainer accepts the work. Branch protection adds the same rule on the repository side. Related: least privilege for coding agents.