Skip to main content

Configure source branch deletion after merge

Learn how to use the Repository Settings API to configure whether source branches are automatically deleted after a pull request is merged.

All sample requests in this guide include the following path parameters:

Parameter nameDescription
tenantIdYour tenant ID.
starSystemIdID of a star system that includes the repository that you want to configure.
repositoryNameName of a repository. For details, see Supported repositories.

About the source branch deletion after merge

The setting to delete source branch after merge controls the default behavior for source branches in Bitbucket. When you enable it, the source branch is by default deleted after the pull request merge in Bitbucket. You can choose not to delete the source branch during a particular merge.

Default configuration

By default, source branch deletion after merge is disabled. You can configure it separately for each repository in your Dev star system.

Note:

With the Repository Settings API, you can't modify the configuration at the Bitbucket project level.


Get configuration

To retrieve the current source branch deletion configuration for a repository, send the following GET request:

curl -X 'GET' \
'{baseUrl}/api/v1/tenants/{tenantId}/starsystems/{starSystemId}/repository/{repositoryName}/branches/deletion-after-merge' \
-H 'accept: application/json' \
-H 'Authorization: Bearer {access_token}'

The response contains a JSON object with the current configuration, for example:

Example response
{
"enabled": false
}

Update configuration

To update the configuration of the source branch deletion for a repository, send the following PUT request:

curl -X 'PUT' \
'{baseUrl}/api/v1/tenants/{tenantId}/starsystems/{starSystemId}/repository/{repositoryName}/branches/deletion-after-merge' \
-H 'Accept: application/json' \
-H 'Authorization: Bearer {access_token}' \
-H 'Content-Type: application/json' \
-d '{body}'

Where {body} contains the updated configuration. For example, to enable automatic branch deletion:

Request body
{
"enabled": true
}

For a successful request, you will receive the 200 status code and the updated configuration:

Example response
{
"enabled": true
}