You're on your way to the next level! Join the Kudos program to earn points and save your progress.
Level 1: Seed
25 / 150 points
1 badge earned
Challenges come and go, but your rewards stay with you. Do more to earn more!
What goes around comes around! Share the love by gifting kudos to your peers.
Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!
Join now to unlock these features and more
Is there any way to restrict branch creation if a branch already exists matching some pattern? Or is there a way to enforce a limit on the number of branches with a certain prefix, e.g. `release/`, such that there can only be one branch with that prefix at a time?
I would be looking for Bitbucket to enforce restrictions on branch creation within Bitbucket (regardless of which branch is the source), as well as applying them in the form of one or more hooks run when someone pushes a local branch to the remote.
I found this https://community.atlassian.com/t5/Bitbucket-questions/Branch-Permissions-to-restrict-branch-creation/qaq-p/661315 but it's 5 years old and it's not clear that it's relevant to Bitbucket Cloud.
Hi @Max DeCurtins ,
In Bitbucket Cloud, you can set branches permissions and branching model for each repository separately:
I hope this helps.
Of course I read your question... Your comment is not nice, stay calm and gentle please.
I was mentioning the doc of Bitbucket Cloud cause first a part of your need can be done on repository level directly on the repo config. Before looking at hooks and stuff around, have a look at what's possible to do directly in the repo settings.
The apps Jira Hooks for Bitbucket mentioned in https://community.atlassian.com/t5/Bitbucket-questions/Branch-Permissions-to-restrict-branch-creation/qaq-p/661315 is not compatible for Bitbucket Cloud:
Again branch creations based on patterns and permissions can be done on each repo with Bitbucket Cloud features.
There is even more doc here: https://bitbucket.org/blog/take-control-with-branch-restrictions. Enforcing a limit on the number of branches with a certain pattern is apparently not possible but you can limit the number of users allowed to create them which will limit the possible branch creator by pattern.
My apologies, I had no intention to be rude. I did, however, ask a specific question. I have spent a good amount of time in Repository Settings and I'm familiar with the options available there.
Your comment: "Enforcing a limit on the number of branches with a certain pattern is apparently not possible but you can limit the number of users allowed to create them which will limit the possible branch creator by pattern." This addresses my question, thank you. I'm seeking to limit the number of branches with a certain pattern, and it is, as you say, likely not possible. I have no need to limit who is allowed to create branches because we are all co-equal devs on my team and anyone is allowed to create any type of branch; what I am seeking to do is implement some automated guards to make sure that we are all more careful about adhering to particular workflows.
> I am seeking to do is implement some automated guards to make sure that we are all more careful about adhering to particular workflows.
I see better now what you need also... I think you can find a possible solution with git hooks... and Bitbucket support git hooks. There is a nice doc about that here: https://www.atlassian.com/git/tutorials/git-hooks
Of course you will have to code the hook according to your needs, but there is
pre-receive hook that can help...
Again I hope this helps.
It's an interesting topic :)