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?
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.
Mark helpful posts with Accept as Solution to help other users locate important info. Don't forget to give Kudos for great content!
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.