Enterprise-level ruleset
Enterprise admins can create rulesets that apply across selected organizations and repositories in the enterprise. Use an enterprise-level ruleset to enforce consistent branch protection policies across many repositories. Steps to create an enterprise ruleset:- From an enterprise admin account, create a new branch ruleset.
- Give the ruleset a name (for example,
Enterprise Clean Protection). - Choose an enforcement mode:
Activeto enforce, orEvaluateto preview the impact without blocking workflows. Learn more about Evaluate mode in the GitHub docs: https://docs.github.com/en/organizations/keeping-your-organization-secure-with-repository-rulesets/about-repository-rulesets. - Target the scope of repositories (organize by organization, repository visibility, etc.).
- Configure branch targeting (for example target
mainby pattern). - Select the branch protection requirements you want enforced (e.g., require a pull request before merging, minimum approvals).

- In this demo we apply the ruleset to all organizations in the enterprise and filter target repositories to private repositories only.

- Include the default branch (for example
main) by pattern. - Enable required protections such as:
Require a pull request before mergingRequire at least 1 approving review before merging
Testing enterprise-level enforcement
Open a repository targeted by the enterprise ruleset (for example: App Backend). In the repository Settings > Rulesets you’ll see the enterprise-level ruleset listed as managed by the enterprise; developers can view but cannot edit enterprise-managed rules. When attempting a direct commit to the protected branch (for example editingREADME on main) GitHub will block the direct commit and prompt you to create a new branch and open a pull request:


Organization-level ruleset
Organization rulesets allow more granular control within a single org while still applying across multiple repositories in that org. Steps to create an organization ruleset:- In the organization: Settings > Repositories > Rulesets, create a new branch ruleset.
- Name the ruleset (for example
Organization Port Scanning Ruleset) and set enforcement toActive. - Target repositories in the organization (you can target all repos or filter specific ones).
- Target branch patterns (for example
main). - Add required checks such as
Require code scanning resultsand choose a minimum alert severity (for examplehighorcritical). If CodeQL is not configured or not producing results for the target branch, the rule will block merges until a successful scan exists.


Repository-level ruleset
Repository-level rulesets let you set protections specific to a single repository. When multiple rulesets apply, GitHub enforces the strictest requirement for each protection type. Example workflow (App Backend):- Create a branch ruleset at the repository level named
Repository Multi-PR Approval. - Set it to
Require at least 2 approving reviews before merging. - Save the ruleset.

- The required number of approving reviews (2) must be obtained (repository-level requirement).
- The required code scanning results (as required by the organization-level ruleset) must be present and meet the configured minimum severity.
Bypassing rulesets
You can grant specific actors a bypass to skip ruleset protections. Bypasses can be granted to roles such as enterprise owners, organization admins, or repository admins and can be scoped to fully bypass or only bypass for pull requests.
If you want to preview the impact of a ruleset before enforcing it, use Evaluate mode. Evaluate mode reports how the rules would behave without blocking developer workflows.
Use bypass lists sparingly. Granting bypass privileges lets actors override protections and can weaken repository security if misused. Ensure bypass entries are limited to trusted roles and documented in your governance policy.
Summary
- Rulesets can be applied at the enterprise, organization, or repository level to enforce branch protection and security requirements across different scopes.
- When multiple rulesets apply, GitHub enforces the strictest protection for each requirement type (e.g., higher number of required reviewers wins).
- Code scanning (CodeQL) requirements must be satisfied on the required branches; missing scans will block merges.
- Bypass privileges must be granted at every applicable level for an actor to fully bypass protections.
- Use
Evaluatemode to test rules without enforcement, and restrict bypass privileges to minimize security risk.
- GitHub repository rulesets docs: https://docs.github.com/en/organizations/keeping-your-organization-secure-with-repository-rulesets/about-repository-rulesets
- CodeQL code scanning docs: https://docs.github.com/en/code-security/code-scanning/using-codeql-code-scanning
- GitHub Copilot: https://docs.github.com/en/copilot