How do I avoid developers from create branches that doesn't follow one of the patterns below?
user-story/W-*
bugfix/W-*
CodePudding user response:
GitHub has branch protection rules which can restrict certain branches, but it doesn't have negative patterns, so there's no way to prevent all patterns but given ones.
Depending on your goal, you can implement a couple of approaches:
- You can set up a CI rule to reject incorrectly named branches. If you protect the main branch and require that check to be green, then people won't be able to merge them.
- You can force users to use a forking model to prevent them from polluting the main repository with invalidly named branches.
I will point out that your proposed policy has the downside that if someone is working on something experimental that doesn't fit into a bug fix or user story, then blocking the creation of those branches altogether (if it were possible) would prevent users from pushing that data to the remote. I've often ended up doing this and at times this work has ended up being really useful, potentially as a base for future work.