Inherit branch restrictions for newly created branch from existing branch

Platform Notice: Cloud Only - This article only applies to Atlassian products on the cloud platform.

Summary

In Bitbucket cloud, the settings are done on the repository level, hence when changes are made on repository level, it would be the same across all branches as well.

When a new branch is created, there is no direct way to inherit the branch restrictions for the newly created branch, the branch restriction on new branch needs to be created manually either from UI or API on the repository level once the branch is created.

Solution

There are three alternatives to achieve this goal:

  • Using specific pattern as branch restriction

    In case you would want to set the restriction for specific pattern, lets say all the release branches, then a branch restriction for a pattern "release/*" can be used as shown below and it would be possible that every time a new branch with the prefix release is created, it would inherit the permission.

    (Auto-migrated image: description temporarily unavailable)
  • Using branch restriction API

    Below branch restriction API can be used from command line directly once the new branch is created, so that the branch restriction can be created.

  • Using branch restriction API from pipeline to automate the process

    This will run the branch restriction api whenever there is a new branch created.

    1 2 3 4 5 6 7 8 pipelines: branches: '**': - step: script: - curl --version - echo "Installed curl version $(curl --version)" - curl -X POST --user "BB_username:App_password" -H "Content-Type:application/json" -d '{"user":[],"kind":"delete", "pattern":"BranchRest", "permission":"write"}' https://bitbucket.org/api/2.0/repositories/{workspace_ID}/{repo_slug}/branch-restrictions

    ℹ️ In case the restriction needs to be created for a specific branch name and for different branch permission, please modify the yaml file accordingly.

Updated on April 2, 2025

Still need help?

The Atlassian Community is here for you.