
Why protect source code?
Your source code is a high-value asset. The goal of branch protections and rulesets is to act as a gatekeeper — preventing unreviewed changes, destructive operations, or accidentally committed secrets from reaching protected branches and production releases.
The scaling problem with legacy branch protection
Branch protection rules work well for a single repository. At scale — hundreds or thousands of repos — managing the same policy (for example, “require pull request reviews”) across each repo becomes error-prone and slow. Every policy change requires updating each repository individually, which is operationally expensive and risky.

Cascading levels: enterprise, organization, repository
Rulesets can be applied at multiple levels simultaneously — enterprise, organization, and repository — which is analogous to federal, state, and city building codes:- Enterprise (federal): global, baseline protections that apply to all repositories (no opt-out).
- Organization (state/city): additional requirements for teams or business units.
- Repository (building owner): repository-specific constraints or exceptions.

How multiple rules interact (layering)
When multiple protections apply — e.g., enterprise rulesets, organization rulesets, repository rulesets, tag protections, and legacy branch protections — GitHub evaluates all applicable controls and applies the most restrictive effective setting. Common questions answered by the stacking model:- If an organization ruleset requires 1 PR approval and a repository ruleset requires 2, GitHub enforces 2.
- No repository can relax an enterprise-level requirement.
- Tag protections and rulesets can add protections beyond branch-only legacy settings.


What you can enforce with rulesets
Rulesets provide a wide range of enforcement options suitable for enterprise governance and CI/CD security. Examples include:- Require signed commits to verify author identity
- Block force pushes and branch deletions
- Restrict which users or teams can push or merge
- Require status checks to pass (for example, CodeQL or dependency review)
- Require CI/CD workflows as required status checks (for example, GitHub Actions)

Two key improvements over legacy branch protection
- Bypass list (fine-grained, auditable)
- Legacy model: binary (admins can bypass or nobody can).
- Rulesets: define exactly who may bypass (e.g., an on-call SRE team during incidents) and audit those actions.

- Tag targeting
- Legacy branch protection only applied to branches.
- Rulesets can target tags and patterns (e.g., protect tags that match
v*to prevent accidental deletion of release tags):
Exam tip: Rulesets can target tags while legacy branch protection cannot. When multiple protections apply, GitHub enforces the most restrictive effective policy — plan your enterprise, org, and repo rules accordingly.
Practical guidance and best practices
- Start with an enterprise-level ruleset that enforces baseline safety (signed commits, block force pushes, required status checks).
- Layer organization-level rules for teams with higher risk or compliance needs.
- Use repository-level rules sparingly for exceptions or highly specific requirements.
- Use the bypass list for documented emergency processes and ensure all bypass actions are auditable.
- Use tag targeting to protect release artifacts and consider required CI checks for any tag creation workflow.
Summary
- Rulesets provide centralized, cascading governance: enterprise → organization → repository.
- When multiple protections apply, GitHub aggregates and enforces the most restrictive setting.
- Compared to legacy branch protection, rulesets offer precise bypass controls and tag targeting, enabling better scale and safer enterprise-wide policy enforcement.