Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Github "Branch name pattern" negation

Tags:

regex

github

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 :(

like image 425
Magnus Avatar asked Mar 07 '19 21:03

Magnus


People also ask

Are Github's Branch protection rule patterns regular expressions?

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

How do I block a specific branch in GitHub?

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.

How to check branch names locally before commit in Git?

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.

Is there a fnmatch pattern for GitHub?

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


1 Answers

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

like image 170
Madhu Bhat Avatar answered Sep 22 '22 12:09

Madhu Bhat