Branch Protection on multiple branches #22037
-
I’m wondering if there’s a way to apply branch protections in a regex kind of way. Here’s an example, I have multiple branches like release-1.0 , release-1.1 and I’d like them to all have the same branch protections. More importantly, when I create a new release-2.0 I’d like it to automatically be given branch protection with the same configuration as release-1.0 and release-1.1. One way I’ve done this in other SCM management tools is by specifying a regular expression. Something to the effect of /^release-/ Is this possible? |
Beta Was this translation helpful? Give feedback.
Replies: 24 comments 5 replies
-
Hi @clphillips, Currently it is not possible to apply branch protections automatically in that way. However, we are looking to improve this feature over time, so I will pass on your feedback. In the meantime, you can use the protected branches API endpoint to script some automatic branch protection based on the branch name. Hope this helps! |
Beta Was this translation helpful? Give feedback.
-
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. |
Beta Was this translation helpful? Give feedback.
-
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 |
Beta Was this translation helpful? Give feedback.
-
Hi @opeyrusse, Branch protection rule patterns are based on fnmatch syntax. You could use I hope this helps! Best, Andrea |
Beta Was this translation helpful? Give feedback.
-
Thanks @andreagriffiths11 for your answer. It appears that I also tested this on longer branch names, like “hotfix/client/project/1.7” and only the pattern Thanks a lot for your help. |
Beta Was this translation helpful? Give feedback.
-
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: ?? |
Beta Was this translation helpful? Give feedback.
-
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! |
Beta Was this translation helpful? Give feedback.
-
This would be great. Please! I read in the another post that |
Beta Was this translation helpful? Give feedback.
-
+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. |
Beta Was this translation helpful? Give feedback.
-
Would love this as well |
Beta Was this translation helpful? Give feedback.
-
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. |
Beta Was this translation helpful? Give feedback.
-
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. |
Beta Was this translation helpful? Give feedback.
-
@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? |
Beta Was this translation helpful? Give feedback.
-
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). |
Beta Was this translation helpful? Give feedback.
-
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 |
Beta Was this translation helpful? Give feedback.
-
Thanks for the ping @zutatensuppe, unfortunately I don’t have any updates for you “yet” |
Beta Was this translation helpful? Give feedback.
-
I’d really like to be able to apply a single rule to the whole project as well no matter the branch name. |
Beta Was this translation helpful? Give feedback.
-
@fishercraigj Doesn’t |
Beta Was this translation helpful? Give feedback.
-
Not for me. |
Beta Was this translation helpful? Give feedback.
-
Reviving this thread |
Beta Was this translation helpful? Give feedback.
-
Fast-forward almost five(!) years and still no better solution than this |
Beta Was this translation helpful? Give feedback.
-
there has been no progress in this issue for five years ... 🙃 |
Beta Was this translation helpful? Give feedback.
-
@AndreaGriffiths11 this discussion is set as answered, and I suppose it is as far as OP's question, however most of this discussion pertains to the fnmatch FNM_EXTGLOB feature being enabled so we can do something like "{branchone,branchtwo}". This seems like a very simple change and it has been years without action or indication. I'm concerned this issue is not being taken seriously because the discussion is marked as answered? or it's not being brought up with the relevant team? I don't know, but it's very bothersome to maintain a bunch of branch rules when one would do. |
Beta Was this translation helpful? Give feedback.
-
Hey y'all, Wanted to follow up on the discussion here, we recently introduced a beta of repository rules. One feature is it does allow for defining multiple branch or tag patterns per ruleset. It's still not RegEx or
|
Beta Was this translation helpful? Give feedback.
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.