Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

restrictions on branch creation

Max DeCurtins June 24, 2022

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.

1 answer

0 votes
Dam
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 24, 2022

Hi @Max DeCurtins , 

In Bitbucket Cloud, you can set branches permissions and branching model for each repository separately: 

I hope this helps.

Cheers,
Dam. 

Max DeCurtins June 24, 2022

@Dam thanks for replying but did you read my question? The docs you linked don't provide any information pertinent to my question.

Dam
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 24, 2022

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: 
https://marketplace.atlassian.com/apps/1211959/jira-hooks-for-bitbucket?hosting=server&tab=overview 

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.

Cheers,
Dam. 

Max DeCurtins June 24, 2022

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.

Like Dam likes this
Dam
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 24, 2022

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 :) 

Cheers,
Dam.

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PERMISSIONS LEVEL
Site Admin
TAGS
AUG Leaders

Atlassian Community Events