This version of GitHub Enterprise will be discontinued on This version of GitHub Enterprise was discontinued on 2020-05-23. 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.

Article version: Enterprise Server 2.17

Configuring protected branches

If you're a repository owner or have admin permissions in a repository, you can customize branch protections in the repository and enforce certain workflows, such as requiring more than one pull request review or requiring certain status checks to pass before allowing a pull request to merge.

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.

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*.

You can also set up automatic branch protection for all 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 it more inclusive. For more information about syntax options for branch rules, see the fnmatch documentation.

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 the priority order and other settings for protected branch rules, see "About protected branches."

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

  1. On GitHub Enterprise, 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, you can configure specific branch rule settings.
    Protected branch rule settings
  7. To confirm your branch protection rule, click Create or Save changes.

Further reading

Ask a human

Can't find what you're looking for?

Contact us