Branch Protection on multiple branches

It looks like it has been introduced this weekend. I can now create a protection with wildcards for something like release/* and it will automatically show all branches it affects, presumably also all future ones. Long overdue feature as other repo management systems had this for a while longer already, I’m glad it is here now.

3 Likes

Hello Sfynx,

seeing this new feature, I tried the same approach as you. However despite having many release branches, the branch restriction page is saying that “Applies to 0 branches”.

Must I do something special to make it work ? As suggested I set the pattern to “release/*”.

Many thanks

Hi @opeyrusse,

Branch protection rule patterns are based on fnmatch syntax. You could use releases/v?.? to automatically protect branches like releases/v1.0releases/v2.0, and releases/v2.1. And [1-9]-[0-9]-stable could automatically protect branches like 1-0-stable2-0-stable, and 2-1-stable. To learn more about branch protection checkout configuring protected branches.

I hope this helps!

Best,

Andrea

2 Likes

Thanks @andreagriffiths11 for your answer.

It appears that / are treated specially. For me, the pattern releases* was not matching “releases/v1” but releases/* or any of your suggestions were working.

I also tested this on longer branch names, like “hotfix/client/project/1.7” and only the pattern hotfix/*/*/* was working. Removing intermediate “/” was breaking the pattern. It puzzled me as fnmatch documentation and its examples seem to imply that a standard hotfix/* or at least hotfix/** should have worked.

Thanks a lot for your help.

I am not able to use github api to add branch protection for a branch that does not exists or a branch with wildcard. 

Wanted to automate adding restrictions for all release branches (release/*) for all repos. Seems it does not work today and its a pain to add it manually as we have 100s of repos.

Ex: 

https://api.github.com/repos/:owner/:repo/branches/release/*/protection

Is there a way to do this automagically :slight_smile: ?? 

That’s not possible at this time. However, I will share your feedback with the appropriate teams. I can see how this would be valuable! 

4 Likes

This would be great. Please!

I read in the another post that {master,develop} is not enabled in fnmatch. Can you provide another mechanism? Perhaps a UI with checkboxes as an alternative to pattern matching? That would be great!

17 Likes

+1 on adding support for this.

Looking more at the fnmatch documentation, it looks like there’s a File::FNM_EXTGLOB option that can be passed to enable{master,develop} to work. This option is disabled by default. Enabling it would save so much time for our organization when new feature branches are created that multiple people will work off of.

15 Likes

Would love this as well

Hi @jeffaburt and @trusktr,

Thanks for being here, we actually  have an internal issue discussing this possibility and I’ve added your feedback to it.  Thanks again for reaching out! I’ll come back and post any updates here.

3 Likes

@andreagriffiths11 

Another +1 for getting this enabled.  

I am preparing a migration of 100+ repos to GitHub Enterprise.  The inability to automate (via REST API) branch protection rules for wildcard patterns (such as release/* and feature/*) is going to be major painpoint for us.  

1 Like

@tadms  I think the wildcard patterns support is already available and documented here: https://help.github.com/en/articles/configuring-protected-branches

The request still pending here is for multiple name matches such as a regex OR.   I supposed you could be looking for this?  {release/*,feature/*}   Would this also be supported?

2 Likes

Yes, this is possible through the UI.  But I’m not looking to manually do this 100+ times through the UI. 

My request is to have this functionality with the REST API to be able to do this programmatically (originally requested by ksraju-rms in this thread).  

2 Likes

Hello! @andreagriffiths11 :)

What is the current status of that feature? Where can it be discussed? It would be awesome to be able to use a pattern like {master,release/*,v[0-9]*}.

2 Likes

Thanks for the ping @zutatensuppe, unfortunately I don’t have any updates for you “yet”

I’d really like to be able to apply a single rule to the whole project as well no matter the branch name.

@fishercraigj  Doesn’t * work?

Not for me.  

Can’t you do this with simply * ? 

I’m looking for somethign that would let me do master OR development. Seems like such a common thing, kind of interesting that was overlooked.

2 Likes

Wanted to weign in myself here. Something like {master, develop} would make my life much easier as I help to manage about 28 repositories!

6 Likes