Sub topic 11
How multiple rulesets and branch protection combine
This chapter assumes you know how classic branch protection rules and rulesets work on their own. A single branch can be covered by several rule sources at once, so you need to know what happens when they overlap.
Rules add up
A branch can be governed by any of these at the same time:
- A classic branch protection rule.
- One or more repository rulesets.
- One or more organization rulesets.
GitHub does not pick one source and ignore the rest. It layers them, and the most restrictive version of each rule applies. Rulesets have no priority order and no "last match wins" behavior. That differs from CODEOWNERS, where the last matching pattern wins.
| Setting | Source A | Source B | Effective result |
|---|---|---|---|
| Required approvals | 1 | 2 | 2 |
| Required status checks | `build` | `lint` | Both `build` and `lint` |
| Force pushes | Allowed | Blocked | Blocked |
| Code owner review | Off | Required | Required |
A rule can be tightened by adding a source, but never loosened by it. To relax a rule, you must change or remove the source that imposes it.
Enforcement status is per ruleset
A ruleset in evaluate mode only records what it would have blocked. It adds nothing to the effective rules until you switch it to active. A disabled ruleset does nothing at all. Other active sources keep enforcing while you test a new ruleset.
Bypass is per source
Bypass actors belong to one ruleset. If a team can bypass ruleset A, that does not let it skip ruleset B or a classic rule. The same goes for administrators: enforce_admins in classic protection only affects that rule.
Suppose the platform team is a bypass actor in a ruleset that requires pull requests. A classic rule on the same branch still blocks direct pushes. A push succeeds only if every source allows it, either by passing the rule or by bypassing it in that source.
Inspect the combined result
Do not work out the result by reading each source. Ask GitHub which rules apply to a branch:
gh api repos/OWNER/REPO/rules/branches/mainThe response lists the rules from active rulesets, and each entry names the ruleset it came from. Use it to find which source is blocking you. Classic branch protection rules do not appear in this list, so check the branch settings page or the protection endpoint for those.
Common mistakes
- Adding a ruleset to loosen a classic rule. The classic rule still applies.
- Adding a bypass actor to one ruleset and expecting it to work everywhere.
- Leaving duplicate rules in several sources. Duplicates make it unclear which one to change later.
- Forgetting organization rulesets, which do not show up in the repository's own ruleset list for editing.
Exercise
A branch has a classic rule requiring 1 approval and an active ruleset requiring 2 approvals and a build check. The release team is a bypass actor in the ruleset only. A release engineer opens a pull request with 1 approval and a passing build. Can they merge, and why?
Show answer
Yes, as long as they use the ruleset bypass. The ruleset's 2-approval requirement is bypassed for them, but the classic rule still requires 1 approval, which the pull request has. Without the bypass, the effective requirement would be 2 approvals, so the merge would be blocked.