Sub topic 3
Active, evaluate and disabled enforcement
Assume you know Git branches, pull requests, JSON, and basic GitHub Actions. A ruleset’s enforcement status controls what GitHub does when a change violates it:
- Active blocks the change unless a matching bypass actor is allowed.
- Evaluate records what would have happened but does not block the change. Use it for a trial rollout.
- Disabled does not evaluate or enforce the ruleset.
Overlapping rulesets
Several rulesets can target the same branch. GitHub combines their requirements. A change must satisfy every applicable rule, so overlapping rulesets generally make protection stricter. A bypass actor must be permitted by the applicable rulesets, and one ruleset cannot usually weaken another.
Push rules for files
Push rulesets apply restrictions to content being pushed. They can restrict file paths, file extensions, or file size. For example, a ruleset can reject changes to secrets/, block .pem files, or set a maximum file size. These rules complement branch rules. They do not replace code review or status checks.
{
"type": "file_extension_restriction",
"parameters": {
"restricted_file_extensions": ["pem", "key"]
}
}Manage rulesets as JSON
The REST API represents a ruleset as JSON. The gh CLI can send that JSON directly:
gh api --method POST \
-H "Accept: application/vnd.github+json" \
"/orgs/YOUR_ORG/rulesets" \
--input ruleset.jsonUse GET to export an existing ruleset, edit it under review, and use PATCH with its ruleset ID to update it. Keep JSON in version control, but do not store tokens in it.
Migrate from branch protection
Inventory each branch protection rule first. Recreate its required reviews, status checks, linear history, deletion, and force-push settings in a ruleset. Start in evaluate, compare insights with current behavior, then remove the old protection only after the ruleset covers it.
> callout warning > Test repository and tag patterns carefully. A pattern that matches no references protects nothing.
Roll out and review
Begin with a narrow repository selection and evaluate mode. Review rule insights for blocked operations, likely violations, and bypass use. Fix false matches, then activate the ruleset. Keep bypass access narrow and temporary.
Exercise
Which status should you choose to measure violations without blocking merges?
Show answer
Evaluate. It records the ruleset’s potential effects while allowing the operation.