Can I set branch restrictions to a more specific pattern than a general pattern already configured?
Asked by Mark Dorros:

I have branch restrictions configured for all our release branches (branch name starts with "release-", of which there are many - too many and too dynamic to list all). Is is possible to add restrictions for a single release branch, say release-23.1, without impacting the restrictions for the other release branches?

Details: I have branch restrictions for "release-\*" that forces team members to merge through PRs. But if I create an additional branch restriction for "release-23.1" to only allow merges by Admins, the restrictions from "release-\*" essentially override the more restrictive settings and allow merging from anyone on the team.

Use case: We have long running release branches, and need to prevent commits on a single branch after code freeze, before we go GA, and still allow normal activity on the other release branches.


Answers:
author: Theodora Boudale
body: Hi Mark,

In case branch permissions overlap, the results are specified in the table here:

* <https://support.atlassian.com/bitbucket-cloud/docs/use-branch-permissions/#Branch-permissions-overlap>

If "Merge access via pull requests" is set up as follows:

release-\*  
Merge access via pull requests: Developers, Administrators

release-23.1  
Merge access via pull requests: Administrators

Then both Administrators and Developers will be able to merge to release-23.1

You could change the "Merge access via pull requests" for release-\* to Everybody. Everybody in this case means everybody with write access to the repo. In this case, only Administrators will be able to merge to release-23.1

If you don't want to change "Merge access via pull requests" for release-\* to Everybody, then the only other way I can think of for achieving what you want would be by renaming the branch release-23.1 so that it doesn't overlap with the pattern release-\* and create a separate branch restriction for that branch.

Kind regards,  
Theodora

comments: author: Mark Dorros
body: Thanks, Theodora. If we implemented the first suggestion, then developers (e.g. non-Admins) wouldn't be able to merge to *any* release branches - something we wouldn't want to prevent, since we're only looking to prevent this for one release branch, release-23.1.

Implementing the second suggestion would likely break automation we have for managing different releases - e.g. switching branches, build artifacts, CI, etc.

By any chance, is allowing multiple branch patterns including a negative pattern on the roadmap? For example, being able to set the pattern for one branch restriction to "release-\*, !release-23.1"?


author: Theodora Boudale
body: Hi Mark,

With the first suggestion, all users (with write access) would be able to merge to any release branches, except for release-23.1. Only administrators would be able to merge to release-23.1.

I am talking about a configuration like the following:

![Screenshot 2023-01-09 at 13.13.37.png](https://community.atlassian.com/t5/image/serverpage/image-id/233505i73226F6216944B5E/image-size/large?v=v2&px=999 "Screenshot 2023-01-09 at 13.13.37.png")

![Screenshot 2023-01-09 at 13.14.10.png](https://community.atlassian.com/t5/image/serverpage/image-id/233506i0BBBBDD25DA346B6/image-size/large?v=v2&px=999 "Screenshot 2023-01-09 at 13.14.10.png")

<br />

Is this something that works for you?
> By any chance, is allowing multiple branch patterns including a negative pattern on the roadmap? For example, being able to set the pattern for one branch restriction to "release-\*, !release-23.1"?

This is not on the roadmap at the moment, we have a feature request for allowing multiple branches in the same branch permission: <https://jira.atlassian.com/browse/BCLOUD-22059> I can create one for negating a pattern as well if you'd be interested in that, please feel free to let me know if you would like me to create it.

Kind regards,  
Theodora


author: Mark Dorros
body: Hi Theodora,

I appreciate the detailed examples. We'll give this a try, although it might not be until our next major release in April, if we're unable to try it out now.

No need to enter a request for a negative pattern at this time.

Thanks,

Mark


author: Theodora Boudale
body: Hi Mark,

You are very welcome. If you need anything further, please feel free to reach out.

Kind regards,  
Theodora


Tags: bitbucket-cloud

cloud