Have also been trying to get my head around this this this morning, I believe you(/we) may have to create two identical rules for each branch oddly. At least that's what I believe after reading through:
"No, there isn't a way to do that in the "Apply rule to" box. As
stated in the protected branches documentation, we use the fnmatch
library to match branch names to the match expression. There is a
feature that would allow for matching two rules like that if there is
a flag enabled but we don't enable that flag in our environment."
OR you could use this solution if you want to apply one rule to all branches beginning with or including the same matching phrase:
Branch protection rule patterns are based on fnmatch syntax. You could
use releases/v?.? to automatically protect branches like
releases/v1.0, releases/v2.0, and releases/v2.1. And
[1-9]-[0-9]-stable could automatically protect branches like
1-0-stable, 2-0-stable, and 2-1-stable.
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:
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:
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.
What You Should Not Do
There are multiple other answers claiming that this pattern (or a similar variant) will work 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 (or semicolons, or any other "separator") 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,].