On Github, when you go to branch settings and create a "Branch protection rule", how do I specify any branch other than 'master'? I've tried a bunch of regex-like expressions, but none seem to work :(
As johnfo says in a comment, GitHub's branch protection rule patterns are not regular expressions. In fact, the GitHub documentation mentions that they are specifically Ruby File::FNM_PATHNAME style expressions. This is highly specific (Git itself uses no Ruby code at all).
On GitHub.com, 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.
Luckily , there is a way to check branch names locally before commit, and it all starts with Git hooks. What are Git hooks? Git hooks are scripts that run automatically every time a particular event occurs in a Git repository such as: commit, push, and receive.
There isn't an exact fnmatch pattern for GitHub yet which can resolve to precisely anything other than master, but the pattern closest to it would be: But this would also exclude branches with only m, a, s, t, e, r or branches with only a combination of those letters. Check out more details on the above on GitHub help and the fnmatch documentation
GitHub uses fnmatch
to match against any pattern provided to find out the branches to which the rule applies for branch protection.
There isn't an exact fnmatch
pattern for GitHub yet which can resolve to precisely anything other than master, but the pattern closest to it would be:
*[!master]*
But this would also exclude branches with only m
,a
,s
,t
,e
,r
or branches with only a combination of those letters.
Check out more details on the above on GitHub help and the fnmatch documentation
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With