Github "Branch name pattern" negation

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


I solved this by creating six separate rules:

[!m]*
m[!a]*
ma[!s]*
mas[!t]*
mast[!e]*
maste[!r]*

branch protection rules


What you can do is create a rule with:

master

and then create another rule (after the first one) with:

**/**

Then this second one will apply to all branches except master because master is covered by a previous rule:

enter image description here

Tags:

Regex

Github