Skip to main content

此版本的 GitHub Enterprise Server 将于以下日期停止服务 2026-03-17. 即使针对重大安全问题,也不会发布补丁。 为了获得更好的性能、更高的安全性和新功能,请升级到最新版本的 GitHub Enterprise。 如需升级帮助,请联系 GitHub Enterprise 支持

管理存储库的规则集

可以在存储库中编辑、监视和删除现有规则集,以更改用户与特定分支和标记进行交互的方式。

谁可以使用此功能?

对存储库具有读取访问权限的任何人都可以查看存储库的规则集。 对仓库具有管理员访问权限的人员或者具有“编辑仓库规则”权限的自定义角色可以为仓库创建、编辑和删除规则集并查看规则集见解。 有关详细信息,请参阅“关于自定义存储库角色”。

规则集在具有 GitHub Free 和 GitHub Free(适用于组织)的公共存储库中可用,在具有 GitHub Pro、GitHub Team 和 GitHub Enterprise Cloud 的公共和专用存储库中可用。

After creating a ruleset, you can still make changes to it. For example, you can add rules to better protect your branches or tags, or you can switch your ruleset from "Evaluate" mode to "Active" after testing its effects on the contributor experience for your repository.

You can use the REST and GraphQL APIs to manage rulesets. For more information, see REST API endpoints for rules and Mutations.

提示

If you're the owner of an organization, you can create rulesets at the organization level. You can apply these rulesets to specific repositories in your organization, and to specific branches in those repositories. For more information, see Creating rulesets for repositories in your organization.

Viewing rulesets for a repository

On the "Rulesets" page, anyone with read access to the repository can view the active rulesets targeting a certain branch or tag. You will also see rulesets running in "Evaluate" mode, which are not enforced.

  1. On GitHub, navigate to the main page of the repository.

  2. From the file tree view on the left, select the branch dropdown menu, then click View all branches. You can also find the branch dropdown menu at the top of the integrated file editor.

    Screenshot of the file tree view for a repository. A dropdown menu for branches is expanded and outlined in dark orange.

  3. To the left of the branch name, click .

    提示

    Only branches that have a ruleset have a icon adjacent to their name.

  4. Optionally, to filter the results click the tabs or use the "Search branches" search bar.

  5. Click the name of the ruleset you want to view.

You can also view active ruselets:

  • By adding the /rules slug to the repository's URL. For example, to view the rules of the open source documentation repository at GitHub, you would go to http://github.com/github/docs/rules.

  • In the merge box if there are rules blocking the merging of a pull request.

Editing a ruleset

注意

If a ruleset was created at the organization level, you cannot edit the ruleset from the repository's settings. If you have permission to edit the ruleset, you can do so in your organization's settings. For more information, see Managing rulesets for repositories in your organization.

You can edit a ruleset to change parts of the ruleset, such as the name, bypass permissions, or rules. You can also edit a ruleset to change its status, such as if you want to enable or temporarily disable a ruleset.

  1. On GitHub, navigate to the main page of the repository.

  2. Under your repository name, click Settings. If you cannot see the "Settings" tab, select the dropdown menu, then click Settings.

    Screenshot of a repository header showing the tabs. The "Settings" tab is highlighted by a dark orange outline.

  3. In the left sidebar, under "Code and automation," click Rules, then click Rulesets.

    Screenshot of the sidebar of the "Settings" page for a repository. The "Rules" sub-menu is expanded, and the "Rulesets" option is outlined in orange.

  4. On the "Rulesets" page, click the name of the ruleset you want to edit.

  5. Change the ruleset as required. For information on the available rules, see Available rules for rulesets.

  6. At the bottom of the page, click Save changes.

Deleting a ruleset

提示

If you want to temporarily disable a ruleset but do not want to delete it, you can set the ruleset's status to "Disabled." For more information, see Editing a ruleset.

  1. On GitHub, navigate to the main page of the repository.

  2. Under your repository name, click Settings. If you cannot see the "Settings" tab, select the dropdown menu, then click Settings.

    Screenshot of a repository header showing the tabs. The "Settings" tab is highlighted by a dark orange outline.

  3. In the left sidebar, under "Code and automation," click Rules, then click Rulesets.

    Screenshot of the sidebar of the "Settings" page for a repository. The "Rules" sub-menu is expanded, and the "Rulesets" option is outlined in orange.

  4. Click the name of the ruleset you want to delete.

  5. To the right of the ruleset's name, select , then click Delete ruleset.

    Screenshot of the page for editing a ruleset. Below a button labeled with three dots, an option labeled "Delete ruleset" is outlined in orange.