I mean I want to create one rule and specify multiple branches like dev|master
. But after seeing the doc, I think it is impossible?? Do I have to create two rules just in order to use the same rule to protect two branches?
Git branch protection rules are a powerful configuration option that enables repository administrators to enforce security policies. This helps protect the git branches from unexpected code commits or deletion by any unauthorized person(s) / user group(s).
Each repository can have one or more branches. The main branch — the one where all changes eventually get merged back into, and is called master. This is the official working version of your project, and the one you see when you visit the project repository at github.com/yourname/projectname.
I found a rather ugly way to do this that at least gets in the ballpark (although it would be a lot better if @GitHub would give us something better than fnmatch
with all options off...).
You can use character sets to specify the beginning characters in the repo name, like this:
(Using "main" branch): [dm][ea][vi]* (Using "master" branch): [dm][ea][vs]*
It will match dev
and main
/master
which is what you want, but the second one will also match "mastodon-rules" and "devo-is-my-favorite-band" due to the wildcard. I don't think fnmatch
give you a "zero-or-one" quantifier like the regex ?
so it's pretty restrictive.
Github fnmatch does allow the negation of a character set, so if a rule is catching branches you don't want to include, you might be able to get around that:
(using "main" branch): [dm][ea][vi][!o]* (using "master" branch): [dm][ea][vs][!o]*
This will miss the dev
branch (it will catch develop
and main
/master
though...), but it excludes "devo" so at least 'whip it' won't start playing during your next all-night thrash session with your metalhead buddies.
Admittedly, this is not a very satisfying solution. But with fnmatch this might be the best option available.
One of the other answers here claims that this pattern works just fine:
[main,qa,stage,master]*
DO NOT BE LURED BY THIS SIRENS SONG
The engine treats characters enclosed in square []
brackets as just that: individual characters. Adding commas does not change that behavior.
Square Brackets: "match any one of the enclosed characters"
Star: "match any string of any length"
So, while this pattern will certainly match the words in the brackets, it will also match any string of any length that starts with one of the characters in the brackets: [aegimnqrst,]
.
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