Mike Goddard
Mike Goddard

Reputation: 606

Is there a way to exclude specific branch names/patterns in GitHub branch protection?

I want to enable GitHub branch protection on all branches except those prefixed with "private_", for example. This way, we do not have to enable every new 'non private' branch as it is created.

I cannot find a way, using GitHub's pattern matching/globbing rules, to accomplish this. Something like a "/^private*/" rule would be ideal. Unfortunately, we do not enforce naming conventions, so a "common-prefix*" rule wouldn't help here.

Does anyone know of a way to do this, in the GUI branch protection rules, not via the API?

Thanks in advance!

Upvotes: 4

Views: 6629

Answers (2)

Sri Yogesh Dorbala
Sri Yogesh Dorbala

Reputation: 61

Using **\** as the last branch protection rule applies the branch protection rules for all the branches which do not fall into any of the mentioned branch protection rules.

For example if you have these branches - users-1, users-2, releases-1, releases-2, temp-1, temp2, random

then, branch protections like the below would set:
users-* --> would cover users-1, users-2
releases-* --> would cover releases-1, releases-2
**\** --> would cover everything else temp-1, temp2, random

Upvotes: 4

herodrigues
herodrigues

Reputation: 967

Protected branch rules use patterns from the fnmatch syntax.

They don't work as RegExp expressions, so it's not possible to apply a lookahead expression to match only branches that not start with private_.

What you can do is to apply a prefix for protected branches. For example, all branches named protected_ (or public_) would be the protected.

So you'd need the rule protected_*

Demo: https://repl.it/@herodrigues/LopsidedAwfulPortablesoftware

Upvotes: 0

Related Questions