Rate this page:
The refs resource allows you access branches and tags in a repository. By default, results will be in the order the underlying source control system returns them and identical to the ordering one sees when running "$ git show-ref". Note that this follows simple lexical ordering of the ref names.
GET /2.0/repositories/{workspace}/{repo_slug}/refs
Returns the branches and tags in the repository.
By default, results will be in the order the underlying source control system returns them and identical to the ordering one sees when running "$ git show-ref". Note that this follows simple lexical ordering of the ref names.
This can be undesirable as it does apply any natural sorting semantics, meaning for instance that refs are sorted ["branch1", "branch10", "branch2", "v10", "v11", "v9"] instead of ["branch1", "branch2", "branch10", "v9", "v10", "v11"].
Sorting can be changed using the ?sort= query parameter. When using ?sort=name to explicitly sort on ref name, Bitbucket will apply natural sorting and interpret numerical values as numbers instead of strings.
repository
string
This can either be the repository slug or the UUID of the repository,
surrounded by curly-braces, for example: {repository UUID}
.
string
This can either be the workspace ID (slug) or the workspace UUID
surrounded by curly-braces, for example: {workspace UUID}
.
string
Query string to narrow down the response as per filtering and sorting.
string
Field by which the results should be sorted as per
filtering and sorting. The name
field is handled specially for refs in that, if specified as the sort field, it
uses a natural sort order instead of the default lexicographical sort order. For example,
it will return ['1.1', '1.2', '1.10'] instead of ['1.1', '1.10', '1.2'].
1 2 3 4
curl --request GET \
--url 'https://api.bitbucket.org/2.0/repositories/{workspace}/{repo_slug}/refs' \
--header 'Authorization: Bearer <access_token>' \
--header 'Accept: application/json'
A paginated list of refs matching any filter criteria that were provided.
Content type | Value |
---|---|
application/json |
GET /2.0/repositories/{workspace}/{repo_slug}/refs/branches
Returns a list of all open branches within the specified repository. Results will be in the order the source control manager returns them.
1 2``` $ curl -s https://api.bitbucket.org/2.0/repositories/atlassian/aui/refs/branches?pagelen=1 | jq . { "pagelen": 1, "size": 187, "values": [ { "name": "issue-9.3/AUI-5343-assistive-class", "links": { "commits": { "href": "https://api.bitbucket.org/2.0/repositories/atlassian/aui/commits/issue-9.3/AUI-5343-assistive-class" }, "self": { "href": "https://api.bitbucket.org/2.0/repositories/atlassian/aui/refs/branches/issue-9.3/AUI-5343-assistive-class" }, "html": { "href": "https://bitbucket.org/atlassian/aui/branch/issue-9.3/AUI-5343-assistive-class" } }, "default_merge_strategy": "squash", "merge_strategies": [ "merge_commit", "squash", "fast_forward" ], "type": "branch", "target": { "hash": "e5d1cde9069fcb9f0af90403a4de2150c125a148", "repository": { "links": { "self": { "href": "https://api.bitbucket.org/2.0/repositories/atlassian/aui" }, "html": { "href": "https://bitbucket.org/atlassian/aui" }, "avatar": { "href": "https://bytebucket.org/ravatar/%7B585074de-7b60-4fd1-81ed-e0bc7fafbda5%7D?ts=86317" } }, "type": "repository", "name": "aui", "full_name": "atlassian/aui", "uuid": "{585074de-7b60-4fd1-81ed-e0bc7fafbda5}" }, "links": { "self": { "href": "https://api.bitbucket.org/2.0/repositories/atlassian/aui/commit/e5d1cde9069fcb9f0af90403a4de2150c125a148" }, "comments": { "href": "https://api.bitbucket.org/2.0/repositories/atlassian/aui/commit/e5d1cde9069fcb9f0af90403a4de2150c125a148/comments" }, "patch": { "href": "https://api.bitbucket.org/2.0/repositories/atlassian/aui/patch/e5d1cde9069fcb9f0af90403a4de2150c125a148" }, "html": { "href": "https://bitbucket.org/atlassian/aui/commits/e5d1cde9069fcb9f0af90403a4de2150c125a148" }, "diff": { "href": "https://api.bitbucket.org/2.0/repositories/atlassian/aui/diff/e5d1cde9069fcb9f0af90403a4de2150c125a148" }, "approve": { "href": "https://api.bitbucket.org/2.0/repositories/atlassian/aui/commit/e5d1cde9069fcb9f0af90403a4de2150c125a148/approve" }, "statuses": { "href": "https://api.bitbucket.org/2.0/repositories/atlassian/aui/commit/e5d1cde9069fcb9f0af90403a4de2150c125a148/statuses" } }, "author": { "raw": "Marcin Konopka <mkonopka@atlassian.com>", "type": "author", "user": { "display_name": "Marcin Konopka", "uuid": "{47cc24f4-2a05-4420-88fe-0417535a110a}", "links": { "self": { "href": "https://api.bitbucket.org/2.0/users/%7B47cc24f4-2a05-4420-88fe-0417535a110a%7D" }, "html": { "href": "https://bitbucket.org/%7B47cc24f4-2a05-4420-88fe-0417535a110a%7D/" }, "avatar": { "href": "https://avatar-management--avatars.us-west-2.prod.public.atl-paas.net/initials/MK-1.png" } }, "nickname": "Marcin Konopka", "type": "user", "account_id": "60113d2b47a9540069f4de03" } }, "parents": [ { "hash": "87f7fc92b00464ae47b13ef65c91884e4ac9be51", "type": "commit", "links": { "self": { "href": "https://api.bitbucket.org/2.0/repositories/atlassian/aui/commit/87f7fc92b00464ae47b13ef65c91884e4ac9be51" }, "html": { "href": "https://bitbucket.org/atlassian/aui/commits/87f7fc92b00464ae47b13ef65c91884e4ac9be51" } } } ], "date": "2021-04-13T13:44:49+00:00", "message": "wip
", "type": "commit" } } ], "page": 1, "next": "https://api.bitbucket.org/2.0/repositories/atlassian/aui/refs/branches?pagelen=1&page=2" } ```
1 2Branches support [filtering and sorting](/cloud/bitbucket/rest/intro/#filtering) that can be used to search for specific branches. For instance, to find all branches that have "stab" in their name: ``` curl -s https://api.bitbucket.org/2.0/repositories/atlassian/aui/refs/branches -G --data-urlencode 'q=name ~ "stab"' ``` By default, results will be in the order the underlying source control system returns them and identical to the ordering one sees when running "$ git branch --list". Note that this follows simple lexical ordering of the ref names. This can be undesirable as it does apply any natural sorting semantics, meaning for instance that tags are sorted ["v10", "v11", "v9"] instead of ["v9", "v10", "v11"]. Sorting can be changed using the ?q= query parameter. When using ?q=name to explicitly sort on ref name, Bitbucket will apply natural sorting and interpret numerical values as numbers instead of strings.
repository
string
This can either be the repository slug or the UUID of the repository,
surrounded by curly-braces, for example: {repository UUID}
.
string
This can either be the workspace ID (slug) or the workspace UUID
surrounded by curly-braces, for example: {workspace UUID}
.
string
Query string to narrow down the response as per filtering and sorting.
string
Field by which the results should be sorted as per
filtering and sorting. The name
field is handled specially for branches in that, if specified as the sort field, it
uses a natural sort order instead of the default lexicographical sort order. For example,
it will return ['branch1', 'branch2', 'branch10'] instead of ['branch1', 'branch10', 'branch2'].
1 2 3 4
curl --request GET \
--url 'https://api.bitbucket.org/2.0/repositories/{workspace}/{repo_slug}/refs/branches' \
--header 'Authorization: Bearer <access_token>' \
--header 'Accept: application/json'
A paginated list of branches matching any filter criteria that were provided.
Content type | Value |
---|---|
application/json |
POST /2.0/repositories/{workspace}/{repo_slug}/refs/branches
Creates a new branch in the specified repository.
The payload of the POST should consist of a JSON document that contains the name of the tag and the target hash.
1 2curl https://api.bitbucket.org/2.0/repositories/seanfarley/hg/refs/branches \ -s -u seanfarley -X POST -H "Content-Type: application/json" \ -d '{ "name" : "smf/create-feature", "target" : { "hash" : "default", } }'
This call requires authentication. Private repositories require the caller to authenticate with an account that has appropriate authorization.
The branch name should not include any prefixes (e.g. refs/heads). This endpoint does support using short hash prefixes for the commit hash, but it may return a 400 response if the provided prefix is ambiguous. Using a full commit hash is the preferred approach.
repository:write
string
This can either be the repository slug or the UUID of the repository,
surrounded by curly-braces, for example: {repository UUID}
.
string
This can either be the workspace ID (slug) or the workspace UUID
surrounded by curly-braces, for example: {workspace UUID}
.
1 2 3 4
curl --request POST \
--url 'https://api.bitbucket.org/2.0/repositories/{workspace}/{repo_slug}/refs/branches' \
--header 'Authorization: Bearer <access_token>' \
--header 'Accept: application/json'
GET /2.0/repositories/{workspace}/{repo_slug}/refs/branches/{name}
Returns a branch object within the specified repository.
1 2``` $ curl -s https://api.bitbucket.org/2.0/repositories/atlassian/aui/refs/branches/master | jq . { "name": "master", "links": { "commits": { "href": "https://api.bitbucket.org/2.0/repositories/atlassian/aui/commits/master" }, "self": { "href": "https://api.bitbucket.org/2.0/repositories/atlassian/aui/refs/branches/master" }, "html": { "href": "https://bitbucket.org/atlassian/aui/branch/master" } }, "default_merge_strategy": "squash", "merge_strategies": [ "merge_commit", "squash", "fast_forward" ], "type": "branch", "target": { "hash": "e7d158ff7ed5538c28f94cd97a9ad569680fc94e", "repository": { "links": { "self": { "href": "https://api.bitbucket.org/2.0/repositories/atlassian/aui" }, "html": { "href": "https://bitbucket.org/atlassian/aui" }, "avatar": { "href": "https://bytebucket.org/ravatar/%7B585074de-7b60-4fd1-81ed-e0bc7fafbda5%7D?ts=86317" } }, "type": "repository", "name": "aui", "full_name": "atlassian/aui", "uuid": "{585074de-7b60-4fd1-81ed-e0bc7fafbda5}" }, "links": { "self": { "href": "https://api.bitbucket.org/2.0/repositories/atlassian/aui/commit/e7d158ff7ed5538c28f94cd97a9ad569680fc94e" }, "comments": { "href": "https://api.bitbucket.org/2.0/repositories/atlassian/aui/commit/e7d158ff7ed5538c28f94cd97a9ad569680fc94e/comments" }, "patch": { "href": "https://api.bitbucket.org/2.0/repositories/atlassian/aui/patch/e7d158ff7ed5538c28f94cd97a9ad569680fc94e" }, "html": { "href": "https://bitbucket.org/atlassian/aui/commits/e7d158ff7ed5538c28f94cd97a9ad569680fc94e" }, "diff": { "href": "https://api.bitbucket.org/2.0/repositories/atlassian/aui/diff/e7d158ff7ed5538c28f94cd97a9ad569680fc94e" }, "approve": { "href": "https://api.bitbucket.org/2.0/repositories/atlassian/aui/commit/e7d158ff7ed5538c28f94cd97a9ad569680fc94e/approve" }, "statuses": { "href": "https://api.bitbucket.org/2.0/repositories/atlassian/aui/commit/e7d158ff7ed5538c28f94cd97a9ad569680fc94e/statuses" } }, "author": { "raw": "psre-renovate-bot <psre-renovate-bot@atlassian.com>", "type": "author", "user": { "display_name": "psre-renovate-bot", "uuid": "{250a442a-3ab3-4fcb-87c3-3c8f3df65ec7}", "links": { "self": { "href": "https://api.bitbucket.org/2.0/users/%7B250a442a-3ab3-4fcb-87c3-3c8f3df65ec7%7D" }, "html": { "href": "https://bitbucket.org/%7B250a442a-3ab3-4fcb-87c3-3c8f3df65ec7%7D/" }, "avatar": { "href": "https://secure.gravatar.com/avatar/6972ee037c9f36360170a86f544071a2?d=https%3A%2F%2Favatar-management--avatars.us-west-2.prod.public.atl-paas.net%2Finitials%2FP-3.png" } }, "nickname": "Renovate Bot", "type": "user", "account_id": "5d5355e8c6b9320d9ea5b28d" } }, "parents": [ { "hash": "eab868a309e75733de80969a7bed1ec6d4651e06", "type": "commit", "links": { "self": { "href": "https://api.bitbucket.org/2.0/repositories/atlassian/aui/commit/eab868a309e75733de80969a7bed1ec6d4651e06" }, "html": { "href": "https://bitbucket.org/atlassian/aui/commits/eab868a309e75733de80969a7bed1ec6d4651e06" } } } ], "date": "2021-04-12T06:44:38+00:00", "message": "Merged in issue/NONE-renovate-master-babel-monorepo (pull request #2883)
chore(deps): update babel monorepo to v7.13.15 (master)
Approved-by: Chris "Daz" Darroch ", "type": "commit" } } ```
1 2This call requires authentication. Private repositories require the caller to authenticate with an account that has appropriate authorization. For Git, the branch name should not include any prefixes (e.g. refs/heads).
repository
string
The name of the branch.
string
This can either be the repository slug or the UUID of the repository,
surrounded by curly-braces, for example: {repository UUID}
.
string
This can either be the workspace ID (slug) or the workspace UUID
surrounded by curly-braces, for example: {workspace UUID}
.
1 2 3 4
curl --request GET \
--url 'https://api.bitbucket.org/2.0/repositories/{workspace}/{repo_slug}/refs/branches/{name}' \
--header 'Authorization: Bearer <access_token>' \
--header 'Accept: application/json'
DELETE /2.0/repositories/{workspace}/{repo_slug}/refs/branches/{name}
Delete a branch in the specified repository.
The main branch is not allowed to be deleted and will return a 400 response.
The branch name should not include any prefixes (e.g. refs/heads).
repository:write
string
The name of the branch.
string
This can either be the repository slug or the UUID of the repository,
surrounded by curly-braces, for example: {repository UUID}
.
string
This can either be the workspace ID (slug) or the workspace UUID
surrounded by curly-braces, for example: {workspace UUID}
.
1 2 3
curl --request DELETE \
--url 'https://api.bitbucket.org/2.0/repositories/{workspace}/{repo_slug}/refs/branches/{name}' \
--header 'Authorization: Bearer <access_token>'
Indicates that the specified branch was successfully deleted.
GET /2.0/repositories/{workspace}/{repo_slug}/refs/tags
Returns the tags in the repository.
By default, results will be in the order the underlying source control system returns them and identical to the ordering one sees when running "$ git tag --list". Note that this follows simple lexical ordering of the ref names.
This can be undesirable as it does apply any natural sorting semantics, meaning for instance that tags are sorted ["v10", "v11", "v9"] instead of ["v9", "v10", "v11"].
Sorting can be changed using the ?sort= query parameter. When using ?sort=name to explicitly sort on ref name, Bitbucket will apply natural sorting and interpret numerical values as numbers instead of strings.
repository
string
This can either be the repository slug or the UUID of the repository,
surrounded by curly-braces, for example: {repository UUID}
.
string
This can either be the workspace ID (slug) or the workspace UUID
surrounded by curly-braces, for example: {workspace UUID}
.
string
Query string to narrow down the response as per filtering and sorting.
string
Field by which the results should be sorted as per
filtering and sorting. The name
field is handled specially for tags in that, if specified as the sort field, it
uses a natural sort order instead of the default lexicographical sort order. For example,
it will return ['1.1', '1.2', '1.10'] instead of ['1.1', '1.10', '1.2'].
1 2 3 4
curl --request GET \
--url 'https://api.bitbucket.org/2.0/repositories/{workspace}/{repo_slug}/refs/tags' \
--header 'Authorization: Bearer <access_token>' \
--header 'Accept: application/json'
A paginated list of tags matching any filter criteria that were provided.
Content type | Value |
---|---|
application/json |
POST /2.0/repositories/{workspace}/{repo_slug}/refs/tags
Creates a new tag in the specified repository.
The payload of the POST should consist of a JSON document that contains the name of the tag and the target hash.
1 2curl https://api.bitbucket.org/2.0/repositories/jdoe/myrepo/refs/tags \ -s -u jdoe -X POST -H "Content-Type: application/json" \ -d '{ "name" : "new-tag-name", "target" : { "hash" : "a1b2c3d4e5f6", } }'
This endpoint does support using short hash prefixes for the commit hash, but it may return a 400 response if the provided prefix is ambiguous. Using a full commit hash is the preferred approach.
repository:write
string
This can either be the repository slug or the UUID of the repository,
surrounded by curly-braces, for example: {repository UUID}
.
string
This can either be the workspace ID (slug) or the workspace UUID
surrounded by curly-braces, for example: {workspace UUID}
.