Sub topic 1
What repository rulesets are and why they exist
Prerequisites
This chapter assumes you know basic Git branches and pull requests, understand GitHub organisations and repository roles, and can read simple JSON. You should also know that GitHub Actions workflows can publish status checks.
A repository ruleset is a named policy that controls changes to branches, tags, or selected file paths. It combines a target, conditions, rules, bypass actors, and an enforcement status. For example, a ruleset can require a pull request and an approval before anyone updates the default branch.
Rulesets solve a scaling problem. Classic branch protection rules usually describe one branch pattern in one repository. An organisation ruleset can apply the same policy across many repositories. Rulesets can also be layered, inspected, and rolled out in an evaluation mode before enforcement.
Repository rulesets and organisation rulesets
A repository ruleset is managed within one repository. Use it when a project has local requirements, such as a release tag policy.
An organisation ruleset is managed at the organisation level. It can target all repositories, selected repositories, or all repositories except an exclusion list. Use it for shared controls such as required reviews or a common workflow. Repository administrators may have less control over an organisation ruleset than over a local rule.
| Scope | Best use | Selection |
|---|---|---|
| Repository | Project-specific policy | One repository |
| Organisation | Shared policy | Many repositories, with include and exclude conditions |
Targeting branches and tags with name patterns
A ruleset can target branches, tags, or both. Its ref conditions use include and exclude patterns. The special pattern ~DEFAULT_BRANCH means the repository’s configured default branch, even when repositories use different names. You can also target names such as release/* or v*.
Keep branch and tag policies separate when their risks differ. A branch rule might require reviews, while a tag rule might prevent deletion.
Choosing which repositories a ruleset applies to
Start with the narrowest useful repository set. Select repositories by name, repository property, or an organisation-wide pattern, then exclude exceptions such as experimental or sandbox repositories. Review exclusions regularly because a new repository may otherwise inherit a policy unexpectedly.
Exercise
Why might an organisation ruleset use ~DEFAULT_BRANCH instead of including main?
Show answer
Repositories can use different default branch names, while ~DEFAULT_BRANCH follows each repository’s configured default.