Skip to main content
This guide demonstrates how to configure GitHub repository rulesets at the enterprise, organization, and repository levels and how those rulesets interact to produce the effective branch protection applied to repositories. You’ll see how to create rulesets, target scope, require code scanning (CodeQL), and manage bypass lists, with examples and screenshots from a sample enterprise and a repository named App Backend.

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:
  1. From an enterprise admin account, create a new branch ruleset.
  2. Give the ruleset a name (for example, Enterprise Clean Protection).
  3. Choose an enforcement mode: Active to enforce, or Evaluate to 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.
  4. Target the scope of repositories (organize by organization, repository visibility, etc.).
  5. Configure branch targeting (for example target main by pattern).
  6. Select the branch protection requirements you want enforced (e.g., require a pull request before merging, minimum approvals).
A dark-themed GitHub Enterprise settings page showing "Repository rulesets / New branch ruleset" where a ruleset name is being entered and the enforcement status dropdown (Active / Evaluate / Disabled) is open. The left sidebar shows repository policy navigation and the main pane includes options like bypass list and target organizations.
Example: target scope and visibility
  • In this demo we apply the ruleset to all organizations in the enterprise and filter target repositories to private repositories only.
A dark-themed GitHub settings screenshot showing an enterprise ruleset configuration page with sections for Actors (bypass list), Target organizations, Target repositories, and Branch targeting. The bypass list is empty and branch targeting has not been configured.
Branch targeting and enforcement options
  • Include the default branch (for example main) by pattern.
  • Enable required protections such as:
    • Require a pull request before merging
    • Require at least 1 approving review before merging
Save the ruleset by clicking Create.

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 editing README on main) GitHub will block the direct commit and prompt you to create a new branch and open a pull request:
During PR creation the UI will indicate any ruleset-imposed requirements (for example at least one approving reviewer required by the enterprise rule). You may proceed to create the PR or save it for later.
A dark-themed GitHub "Open a pull request" page showing a branch comparison, title and description fields, and a green "Create pull request" button. The right sidebar lists reviewers, assignees, labels and other PR metadata.
You can also add additional branch rules (for example, block force pushes). These options appear on the repository Branch rules settings and will be enforced as part of the effective protection.
A screenshot of a GitHub repository's Branch rules settings page. It shows checkboxes for rules like restricting creations/updates/deletions, requiring linear history or signed commits, and selected options such as "Require a pull request before merging" and "Block force pushes."

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:
  1. In the organization: Settings > Repositories > Rulesets, create a new branch ruleset.
  2. Name the ruleset (for example Organization Port Scanning Ruleset) and set enforcement to Active.
  3. Target repositories in the organization (you can target all repos or filter specific ones).
  4. Target branch patterns (for example main).
  5. Add required checks such as Require code scanning results and choose a minimum alert severity (for example high or critical). If CodeQL is not configured or not producing results for the target branch, the rule will block merges until a successful scan exists.
Use the repository filter modal to target which repos should receive the org-level ruleset.
A dark-mode GitHub settings screen with a "Filter" modal open to select target repositories. The modal shows a search box and filter options (Visibility, Fork, Deployable, Deployed, Language, Exclude) plus Cancel and Apply buttons.
After selecting a code scanning requirement (e.g., CodeQL), create the organization ruleset.
A dark-themed screenshot of a GitHub repository rules/settings page showing code scanning (CodeQL) and merge requirement options. The page lists checkboxes for require code quality results, restrict code coverage, request Copilot review, license compliance and other restrictions, with a green "Create" button at the bottom.

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):
  1. Create a branch ruleset at the repository level named Repository Multi-PR Approval.
  2. Set it to Require at least 2 approving reviews before merging.
  3. Save the ruleset.
Because both the enterprise-level rule (1 approving review) and repository-level rule (2 approvals) apply, GitHub enforces the stricter requirement: 2 approvals. Edit the README on the default branch; GitHub will prompt to open a PR. The PR UI now shows the repository-level requirement of two approvals.
A GitHub "Open a pull request" page in dark mode for the game-devstudio/app-backend repository, showing branch comparison and a "Create pull request" button. The title field reads "Update README header to include 'edit 2'" and there are fields for description, reviewers, and other metadata.
Proposed change in the PR:
Conditions blocking merge
  • 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.
Important: if code scanning (CodeQL) is not configured or is not producing results on the relevant branch, the organization-level requirement will block the merge. Code scanning requirements typically expect scan results for the branch being merged (and sometimes the default branch); missing results cause the merge to be prevented. Comparison: ruleset levels and impact

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.
A screenshot of a GitHub Enterprise "Repository rulesets" settings page for the ruleset named "enterprise-main-protection," showing enforcement as Active and an "Add bypass" dialog listing actors like Enterprise owners, Copilot, and Dependabot. The left sidebar displays Policies and other enterprise settings navigation.
Important: a user or role can bypass protections only if they are included in the bypass lists for every enforced ruleset that applies to the repository (enterprise, organization, and repository). In the demo, granting a bypass at only the enterprise or organization level did not permit merging until a corresponding bypass was added at the repository level. After adding matching bypass actors at all applicable levels, the PR could be merged without satisfying the approval and code scanning requirements.
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 Evaluate mode to test rules without enforcement, and restrict bypass privileges to minimize security risk.
Links and references

Watch Video