Github Branch protection rule, pattern for set branch names

Viewed 2465

i'm trying to set rules for set branches on my repo, but having issues with the pattern to apply only to specific branches. ie rule to apply only to brances master,develop,release

Issue: the pattern isn't picking up the wrong branches

I tried looking through here, but it's working as expected https://ruby-doc.org/core-2.5.1/File.html#method-c-fnmatch

I've tried, but not working with 0 branches or everything selected:

{^.*(master).*$,^.*(develop).*$} [master,develop,release] [master;develop;release]*

ps this one dose the opposite an applied all brances, but the listed ones: *[!master|!develop|!release]*

3 Answers

I have a work around, but i'm sure there is a better solution, or rite solution for this. I basically use the oder of precedence of the rules to have only set branches with the rules i want.

  • I target every branch except the ones I want, and set no rule.
  • Then set all branches to require the rule i want to apply to my branches.
  • The first rule takes president and ensures that only the ones i want, get the rule.

NB there is a conflict raised in the rule, be this seems more like a warning

enter image description here

You can try [dm]*[pr] for branches starting with 'd' or 'm' and ending with 'p' or 'm' (for develop and master). I'm sure this can be further refined.

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

I snipped the tag; curiously, you included yourself, which is the right tag for someone who might like to supply the right Ruby expressions here. It looks like GitHub do not set the FNM_EXTMATCH flag, so you probably need multiple match expressions (also noted in the comment above). I wouldn't bother answering except that it seemed useful to add some links.

Related