

Under "Protect matching branches", select Require a pull request before merging. Optionally, enable required pull requests. Under "Branch name pattern", type the branch name or pattern you want to protect. Next to "Branch protection rules", click Add rule.

In the "Code and automation" section of the sidebar, click Branches. If you cannot see the "Settings" tab, select the dropdown menu, then click Settings. Under your repository name, click Settings. On, navigate to the main page of the repository. When you create a branch rule, the branch you specify doesn't have to exist yet in the repository. For information about an alternative to branch protection rules, see " About rulesets." Creating a branch protection rule Tip: Only a single branch protection rule can apply at a time, which means it can be difficult to know how which rule will apply when multiple versions of a rule target the same branch. 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.įor more information about each of the available branch protection settings, see " About protected branches." 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. 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. 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. You can also extend the qa string with qa**/**/* to make the rule more inclusive.įor more information about syntax options, see the fnmatch documentation. You can include any number of slashes after qa with qa/**/*, which would match, for example, qa/foo/bar/foobar/hello-world. For example, qa/* will match all branches beginning with qa/ and containing a single slash, but will not match qa/foo/bar. Because GitHub uses the File::FNM_PATHNAME flag for the File.fnmatch syntax, the * wildcard does not match directory separators ( /). You can create a rule for all current and future branches in your repository with the wildcard syntax *. For example, to protect any branches containing the word release, you can create a branch rule for *release*. However, it is technically feasible, so I mention it here for completeness.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. That's a lot of work for a very small pay-off, since you could get the same benefit with less work with a clone. For example, you might use semaphore files (such as those created by lockfile from the lockfile-progs package) or flock in a wrapper script that turns off write or execute permissions on your shared directory before kicking off some long-running build process. You could certainly design your own scripts to abuse the shared-repository model. Abusing Shared Repositories with Semaphores There are certainly some use cases for the shared repository model. By definition, any shared repository can have the working directory modified by anyone with the necessary permissions, so you shouldn't be using a shared repository if you need to ensure a stable working directory during the lifetime of some process. Unless you are using a shared repository configured with core.sharedRepository enabled, you should be pushing to a bare repository and running any continuous integration or build systems off a non-bare clone. Some SCMs that support optional locks include SVN, CVS, and RCS. If you want an SCM with locking, use something else with a centralized-repository model.
