Help
cancel
Showing results for 
Search instead for 
Did you mean: 
Ground Controller Lvl 1
Message 1 of 4

How to prevent pushing new branch whose name match exising protection rule

We have branch protection rule 'stable-v*' to protect existing branches like stable-v1.0 and stable-v2.0, to prevent our team member from pushing into these branch directly. However, this rule can not restrict new branch matching the same pattern to be pushed accidently. Once pushed, the new branch will be protected and not be easy to remove. 

As the adminitrator, I have to disable the rule first, delete the branch, then re-enabled the rule.

 

Is there any method to prevent our team member to push such branch? 

3 Replies
Community Manager
Message 2 of 4

Re: How to prevent pushing new branch whose name match exising protection rule

Hi @dummyhuan,

 

Thank you for being here! I can't think of any obvious way to significantly improve your method. We're always working to improve GitHub, and we consider every suggestion we receive. I've logged this as a feature request in our internal feature request list. Though I can't guarantee anything or share a timeline for this, I can tell you that it's been shared with the appropriate teams for consideration.

 

Best,

Andrea


Best,
AndreaG

Mark helpful posts with Accept as Solution to help other users locate important info. Don't forget to give Kudos for great content!

Copilot Lvl 2
Message 3 of 4

Re: How to prevent pushing new branch whose name match exising protection rule

Hi @AndreaGriffiths11,


I consider it a pretty bad UX to have branch protection rules restricting who can push only apply after a branch has been pushed for the first time. The hook that GitHub uses should ideally check the name of the branch being created for existing protection rules and apply them as if it was an existing branch to which someone was trying to push.

 

I have tried using a * pattern to prevent pushing new branches to our repo (we only accept PRs from forks) to discover that this was just not working as expected.

Ground Controller Lvl 1
Message 4 of 4

Re: How to prevent pushing new branch whose name match exising protection rule

I agree with @Zimmi48 , this seems more like a bug in the "branch protection" feature at the moment, unless I'm missing something about the rational for the current behavior. @AndreaGriffiths11  do you have more information on this?