How to apply github branch rules to two branches?
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:
[dm][ea][vs]*
It will match dev
and master
which is what you want, but it 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:
[dm][ea][vs][!o]*
This will miss the dev
branch (it will catch develop
thought...), 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.
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:
https://github.community/t5/How-to-use-Git-and-GitHub/Apply-a-single-branch-protection-rule-to-both-master-and-release/td-p/11587
Comment from Moderator:
"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:
https://github.community/t5/How-to-use-Git-and-GitHub/Branch-Protection-on-multiple-branches/td-p/10519
Comment from Community Manager:
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.