Sub topic 10
How overlapping rulesets combine
This chapter assumes you can read a ruleset JSON body, and that you know the difference between repository-level and organisation-level rulesets. It also assumes you have seen the rule types for pull requests and status checks. Here you learn what happens when more than one ruleset matches the same branch.
Rulesets add up
Several rulesets can target the same branch. This is normal. An organisation ruleset might protect every default branch, while a repository ruleset adds a stricter rule for one repository.
GitHub does not pick a winning ruleset. It collects the rules from every active ruleset that matches the branch and applies all of them together. A change must satisfy every rule from every matching ruleset.
Rulesets also combine with classic branch protection rules. If both apply to a branch, the stricter result for each setting is what you see in practice.
How each kind of rule combines
Most rules are simple on or off switches, so the union is easy to predict. Rules with numbers or lists follow a few patterns.
| Rule | Ruleset A | Ruleset B | Combined effect |
|---|---|---|---|
| Required approving reviews | 1 | 2 | 2 reviews needed |
| Code owner review | on | off | Required |
| Force push block (`non_fast_forward`) | present | absent | Blocked |
| Required status checks | `build` | `lint` | Both `build` and `lint` must pass |
| Required workflows | `org-ci.yml` | `security.yml` | Both workflows must pass |
Numeric settings take the highest value. Boolean settings that make a rule stricter win over those that do not. Lists of required checks or workflows are merged, not replaced.
A repository ruleset cannot weaken an organisation ruleset. It can only add to it. If you need an exception, give a bypass actor to the organisation ruleset itself.
Bypass is per ruleset
Bypass actors belong to one ruleset. They do not carry over to other rulesets that match the same branch.
Suppose repository admins can bypass ruleset A through a pull request. Ruleset B matches the same branch and has no bypass list. Admins can skip A's rules but must still satisfy B's. To let a group skip every rule, add it to each ruleset that matches.
Enforcement status affects the result
Only rulesets whose enforcement is active block changes. A ruleset set to evaluate records what it would have done but does not block anything. A disabled ruleset has no effect. Use this to test a new overlap before it can stop anyone's work.
Worked example
An organisation has two rulesets that match the main branch of the repository payments.
protect-default-branch(organisation, active): blocks deletion and force pushes, requires 1 approving review.payments-extra(repository, active): requires 2 approving reviews and theintegration-testsstatus check.
The effective rules for payments/main are the following:
- Deletion and force pushes are blocked, from the organisation ruleset.
- 2 approving reviews are required, because 2 is higher than 1.
- The
integration-testscheck must pass, from the repository ruleset.
For a repository named sandbox-demo, the organisation ruleset excludes it by name. Only repository-level rules, if any, would apply there.
Checking the result
To see which rulesets apply to a branch, use the "Rulesets" view in the repository settings. You can also query the rules that apply to a branch with the API:
gh api /repos/YOUR_ORG/payments/rules/branches/mainThe response lists each rule along with the ruleset that supplied it. This is the quickest way to find the source of an unexpected requirement.
Exercise
Ruleset A (organisation, active) requires 1 approving review and lets the role "Maintain" bypass through a pull request. Ruleset B (repository, active) requires 3 approving reviews and has no bypass actors. A maintainer opens a pull request on a branch that both rulesets match. How many approvals are needed, and can the maintainer bypass?
Show answer
Three approvals are needed, because numeric settings take the highest value. The maintainer cannot bypass ruleset B, since bypass is defined per ruleset and B has no bypass actors. The maintainer must therefore meet B's rules even though A would allow a bypass.