配置受保护分支
如果您是仓库所有者或者拥有仓库管理员权限,您可以自定义仓库中的分支保护和实施某些工作流程,例如要求在合并拉取请求之前进行多次拉取请求审查或某些状态检查。
受保护分支适用于具有 GitHub Free 的公共仓库,以及具有 GitHub Pro、GitHub Team、GitHub Enterprise Cloud 及 GitHub Enterprise Server 的公共和私有仓库。
You can create a branch rule in a repository for a specific branch, all branches, or any branch that matches a naming pattern specified with the fnmatch syntax. For example, to require any branch containing the word release
to have at least two pull request reviews before merging, you can create a branch rule for *release*
.
您还可以使用通配符语法 *
为仓库中的所有分支设置自动分支保护。 Because GitHub uses the File::FNM_PATHNAME
flag for the File.fnmatch
syntax, the wildcard does not match directory separators (/
). For example, qa/*
will match all branches beginning with qa/
and containing a single slash. 您可以通过 qa/**/*
包含多个斜杠,也可以通过 qa**/**/*
扩展 qa
字符串,使其更具包容性。 有关分支规则语法选项的更多信息,请参阅 fnmatch 文档。
要创建对现有分支规则的例外,您可以创建优先级更高的新分支保护规则,例如针对特定分支名称的分支规则。 有关受保护分支规则的优先级顺序及其他设置的更多信息,请参阅“关于受保护分支”。
注:创建分支规则时,指定的分支不必是仓库中现有的分支。
-
On GitHub Enterprise, navigate to the main page of the repository.
-
Under your repository name, click Settings.
-
In the left menu, click Branches.
-
Next to "Branch protection rules", click Add rule.
-
Under "Branch name pattern", type the branch name or pattern you want to protect.
-
(可选)您可以配置特定分支规则设置。
-
要确认分支保护规则,请单击 Create(创建)或 Save changes(保存更改)。