• Addon
  • Branch restrictions
  • Branching model
  • Commit statuses
  • Commits
  • Deployments
  • Downloads
  • GPG
  • Issue tracker
  • Pipelines
  • Projects
  • Pullrequests
  • Refs
  • Reports
  • Repositories
  • SSH
  • Snippets
  • Source
  • Users
  • Webhooks
  • Workspaces
  • Other operations
Cloud
Bitbucket Cloud / Reference / REST APIs

Branch restrictions

Postman Collection
OpenAPI

Repository owners and administrators can set branch management rules on a repository that control what can be pushed by whom. Through these rules, you can enforce a project or team workflow. For example, owners or administrators can:

  • Limit push powers
  • Prevent branch deletion
  • Prevent history re-writes (Git only)
GET

List branch restrictions

Returns a paginated list of all branch restrictions on the repository.

Scopes
repository:admin
admin:repository:bitbucket

Request

Path parameters

repo_slug

string

Required
workspace

string

Required

Query parameters

kind

string

pattern

string

Responses

A paginated list of branch restrictions

application/json

Paginated Branch Restrictions

A paginated list of branch restriction rules.

GET/repositories/{workspace}/{repo_slug}/branch-restrictions
1 2 3 4 curl --request GET \ --url 'https://api.bitbucket.org/2.0/repositories/{workspace}/{repo_slug}/branch-restrictions' \ --header 'Authorization: Bearer <access_token>' \ --header 'Accept: application/json'
200Response
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 { "size": 142, "page": 102, "pagelen": 159, "next": "<string>", "previous": "<string>", "values": [ { "type": "<string>", "links": { "self": { "href": "<string>", "name": "<string>" } }, "id": 34, "kind": "push", "branch_match_kind": "branching_model", "branch_type": "feature", "pattern": "<string>", "value": 473, "users": [ { "type": "<string>" } ], "groups": [ { "type": "<string>" } ] } ] }
POST

Create a branch restriction rule

Creates a new branch restriction rule for a repository.

kind describes what will be restricted. Allowed values include: push, force, delete, restrict_merges, require_tasks_to_be_completed, require_approvals_to_merge, require_default_reviewer_approvals_to_merge, require_no_changes_requested, require_passing_builds_to_merge, require_commits_behind, reset_pullrequest_approvals_on_change, smart_reset_pullrequest_approvals, reset_pullrequest_changes_requested_on_change, require_all_dependencies_merged, enforce_merge_checks, and allow_auto_merge_when_builds_pass.

Different kinds of branch restrictions have different requirements:

  • push and restrict_merges require users and groups to be specified. Empty lists are allowed, in which case permission is denied for everybody.

The restriction applies to all branches that match. There are two ways to match a branch. It is configured in branch_match_kind:

  1. glob: Matches a branch against the pattern. A '*' in pattern will expand to match zero or more characters, and every other character matches itself. For example, 'foo*' will match 'foo' and 'foobar', but not 'barfoo'. '*' will match all branches.
  2. branching_model: Matches a branch against the repository's branching model. The branch_type controls the type of branch to match. Allowed values include: production, development, bugfix, release, feature and hotfix.

The combination of kind and match must be unique. This means that two glob restrictions in a repository cannot have the same kind and pattern. Additionally, two branching_model restrictions in a repository cannot have the same kind and branch_type.

users and groups are lists of users and groups that are except from the restriction. They can only be configured in push and restrict_merges restrictions. The push restriction stops a user pushing to matching branches unless that user is in users or is a member of a group in groups. The restrict_merges stops a user merging pull requests to matching branches unless that user is in users or is a member of a group in groups. Adding new users or groups to an existing restriction should be done via PUT.

Note that branch restrictions with overlapping matchers is allowed, but the resulting behavior may be surprising.

Scopes
repository:admin
admin:repository:bitbucket

Request

Path parameters

repo_slug

string

Required
workspace

string

Required

Request bodyapplication/json

The new rule

allOf [object, Branch Restriction]

object

Base type for most resource objects. It defines the common type element that identifies an object's type. It also identifies the element as Swagger's discriminator.

Branch Restriction

A branch restriction rule.

Responses

A paginated list of branch restrictions

application/json

allOf [object, Branch Restriction]

object

Base type for most resource objects. It defines the common type element that identifies an object's type. It also identifies the element as Swagger's discriminator.

Branch Restriction

A branch restriction rule.

POST/repositories/{workspace}/{repo_slug}/branch-restrictions
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 curl --request POST \ --url 'https://api.bitbucket.org/2.0/repositories/{workspace}/{repo_slug}/branch-restrictions' \ --header 'Authorization: Bearer <access_token>' \ --header 'Accept: application/json' \ --header 'Content-Type: application/json' \ --data '{ "type": "<string>", "links": { "self": { "href": "<string>", "name": "<string>" } }, "id": 34, "kind": "push", "branch_match_kind": "branching_model", "branch_type": "feature", "pattern": "<string>", "value": 473, "users": [ { "type": "<string>" } ], "groups": [ { "type": "<string>" } ] }'
201Response
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 { "type": "<string>", "links": { "self": { "href": "<string>", "name": "<string>" } }, "id": 34, "kind": "push", "branch_match_kind": "branching_model", "branch_type": "feature", "pattern": "<string>", "value": 473, "users": [ { "type": "<string>" } ], "groups": [ { "type": "<string>" } ] }
GET

Get a branch restriction rule

Returns a specific branch restriction rule.

Scopes
repository:admin
admin:repository:bitbucket

Request

Path parameters

id

string

Required
repo_slug

string

Required
workspace

string

Required

Responses

The branch restriction rule

application/json

allOf [object, Branch Restriction]

object

Base type for most resource objects. It defines the common type element that identifies an object's type. It also identifies the element as Swagger's discriminator.

Branch Restriction

A branch restriction rule.

GET/repositories/{workspace}/{repo_slug}/branch-restrictions/{id}
1 2 3 4 curl --request GET \ --url 'https://api.bitbucket.org/2.0/repositories/{workspace}/{repo_slug}/branch-restrictions/{id}' \ --header 'Authorization: Bearer <access_token>' \ --header 'Accept: application/json'
200Response
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 { "type": "<string>", "links": { "self": { "href": "<string>", "name": "<string>" } }, "id": 34, "kind": "push", "branch_match_kind": "branching_model", "branch_type": "feature", "pattern": "<string>", "value": 473, "users": [ { "type": "<string>" } ], "groups": [ { "type": "<string>" } ] }
PUT

Update a branch restriction rule

Updates an existing branch restriction rule.

Fields not present in the request body are ignored.

See POST for details.

Scopes
repository:admin
admin:repository:bitbucket

Request

Path parameters

id

string

Required
repo_slug

string

Required
workspace

string

Required

Request bodyapplication/json

The new version of the existing rule

allOf [object, Branch Restriction]

object

Base type for most resource objects. It defines the common type element that identifies an object's type. It also identifies the element as Swagger's discriminator.

Branch Restriction

A branch restriction rule.

Responses

The updated branch restriction rule

application/json

allOf [object, Branch Restriction]

object

Base type for most resource objects. It defines the common type element that identifies an object's type. It also identifies the element as Swagger's discriminator.

Branch Restriction

A branch restriction rule.

PUT/repositories/{workspace}/{repo_slug}/branch-restrictions/{id}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 curl --request PUT \ --url 'https://api.bitbucket.org/2.0/repositories/{workspace}/{repo_slug}/branch-restrictions/{id}' \ --header 'Authorization: Bearer <access_token>' \ --header 'Accept: application/json' \ --header 'Content-Type: application/json' \ --data '{ "type": "<string>", "links": { "self": { "href": "<string>", "name": "<string>" } }, "id": 34, "kind": "push", "branch_match_kind": "branching_model", "branch_type": "feature", "pattern": "<string>", "value": 473, "users": [ { "type": "<string>" } ], "groups": [ { "type": "<string>" } ] }'
200Response
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 { "type": "<string>", "links": { "self": { "href": "<string>", "name": "<string>" } }, "id": 34, "kind": "push", "branch_match_kind": "branching_model", "branch_type": "feature", "pattern": "<string>", "value": 473, "users": [ { "type": "<string>" } ], "groups": [ { "type": "<string>" } ] }
DEL

Delete a branch restriction rule

Deletes an existing branch restriction rule.

Scopes
repository:admin
admin:repository:bitbucket

Request

Path parameters

id

string

Required
repo_slug

string

Required
workspace

string

Required

Responses

This status code has no content.

DEL/repositories/{workspace}/{repo_slug}/branch-restrictions/{id}
1 2 3 curl --request DELETE \ --url 'https://api.bitbucket.org/2.0/repositories/{workspace}/{repo_slug}/branch-restrictions/{id}' \ --header 'Authorization: Bearer <access_token>'

Rate this page: