VOOZH about

URL: https://docs.github.com/en/enterprise-server@2.21/github/administering-a-repository/defining-the-mergeability-of-pull-requests/managing-a-branch-protection-rule

⇱ Managing a branch protection rule - GitHub Docs


GitHub Docs

This version of GitHub Enterprise was discontinued on 2021-06-09. No patch releases will be made, even for critical security issues. For better performance, improved security, and new features, upgrade to the latest version of GitHub Enterprise. For help with the upgrade, contact GitHub Enterprise support.

Managing a branch protection rule

You can create a branch protection rule to enforce certain workflows for one or more branches, such as requiring an approving review or passing status checks for all pull requests merged into the protected branch.

People with admin permissions to a repository can manage branch protection rules.

Protected branches are available in public repositories with GitHub Free and GitHub Free for organizations, and in public and private repositories with GitHub Pro, GitHub Team, GitHub Enterprise Cloud, and GitHub Enterprise Server.

About branch protection rules

You can create a branch protection rule in a repository for a specific branch, all branches, or any branch that matches a name pattern you specify with fnmatch syntax. For example, to protect any branches containing the word release, you can create a branch rule for *release*.

You can create a rule for all current and future branches in your repository with the wildcard syntax *. 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. You can include multiple slashes with qa/**/*, and you can extend the qa string with qa**/**/* to make the rule more inclusive. For more information about syntax options for branch rules, see the fnmatch documentation.

If a repository has multiple protected branch rules that affect the same branches, the rules that include a specific branch name have the highest priority. If there is more than one protected branch rule that references the same specific branch name, then the branch rule created first will have higher priority.

Protected branch rules that mention a special character, such as *, ?, or ], are applied in the order they were created, so older rules with these characters have a higher priority.

To create an exception to an existing branch rule, you can create a new branch protection rule that is higher priority, such as a branch rule for a specific branch name.

For more information about each of each of the available branch protection settings, see "About protected branches."

Creating a branch protection rule

When you create a branch rule, the branch you specify doesn't have to exist yet in the repository.

  1. On GitHub Enterprise Server, navigate to the main page of the repository.
  2. Under your repository name, click Settings. 👁 Repository settings button
  3. In the left menu, click Branches. 👁 Repository options sub-menu
  4. Next to "Branch protection rules", click Add rule. 👁 Add branch protection rule button
  5. Under "Branch name pattern", type the branch name or pattern you want to protect. 👁 Branch rule field
  6. Optionally, enable required pull request reviews.
  7. Optionally, enable required status checks.
  8. Optionally, select Require signed commits. 👁 Require signed commits option
  9. Optionally, select Require linear history. 👁 Required linear history option
  10. Optionally, select Include administrators. 👁 Include administrators checkbox
  11. Optionally, enable branch restrictions.
  12. Optionally, under "Rules applied to everyone including administrators", select Allow force pushes. 👁 Allow force pushes option
  13. Optionally, select Allow deletions. 👁 Allow branch deletions option
  14. Click Create.

Editing a branch protection rule

  1. On GitHub Enterprise Server, navigate to the main page of the repository.
  2. Under your repository name, click Settings. 👁 Repository settings button
  3. In the left menu, click Branches. 👁 Repository options sub-menu
  4. To the right of the branch protection rule you want to edit, click Edit. 👁 Edit button
  5. Make your desired changes to the branch protection rule.
  6. Click Save changes. 👁 Save changes button

Deleting a branch protection rule

  1. On GitHub Enterprise Server, navigate to the main page of the repository.
  2. Under your repository name, click Settings. 👁 Repository settings button
  3. In the left menu, click Branches. 👁 Repository options sub-menu
  4. To the right of the branch protection rule you want to delete, click Delete. 👁 Delete button