Deleting a Branch
Deleting Branches Using the CLI
1. Identify the Branch ID:
Retrieve the ID of the branch you want to delete.
2. Use the CLI Command:
Delete a branch
USAGE
$ csdx cm:branches:delete [-uid ] [-k ]
$ csdx cm:branches:delete [--uid ] [--stack-api-key ]
FLAGS
-k, --stack-api-key= Stack API key
-y, --yes Force the deletion of the branch by skipping the confirmation
--uid= Branch UID to be deleted
DESCRIPTION
Delete a branch
EXAMPLES
$ csdx cm:branches:delete
$ csdx cm:branches:delete --uid main -k bltxxxxxxxx
$ csdx cm:branches:delete --uid main --stack-api-key bltxxxxxxxx
$ csdx cm:branches:delete --uid main --stack-api-key bltxxxxxxxx --yes

3. Verify Deletion:
Confirm the successful deletion by checking the list of branches or using the appropriate CLI command to list branches.
csdx cm:branches -k

Conclusion:
Following these step-by-step instructions, you can seamlessly delete branches in Contentstack using the CLI tool.
Deleting Branches Using API Calls
1. Identify API Key and authtoken and Branch ID:
-
Obtain the API KEY of the stack for the branch you wish to delete.
-
Obtain the authtoken for the user.
-
Obtain the unique ID of the branch you wish to delete.
2. Make API Call:
DELETE /v3/stacks/branches/{branch_id}
Replace {branch_id} with the ID of the branch you want to delete.
curl --location --request DELETE 'https://api.contentstack.io/v3/stacks/branches/dev?force=true' \
--header 'api_key: **************' \
--header 'authtoken: *************' \
--header 'Content-Type: application/json' \
--data ''
3. Response:
Upon successful deletion, the response will confirm the removal of the specified branch.
{
"notice": "Your request to delete branch is in progress. Please check organization bulk task queue for more details.",
"branch": {
"uid": "dev",
"source": "main",
"created_by": "******************",
"updated_by": "*******************",
"created_at": "2024-01-23T09:13:09.739Z",
"updated_at": "2024-01-23T09:13:10.714Z",
"deleted_at": false,
"alias": []
}
}

Deleting Branches Using UI
1. Navigate to Branch Settings:
-
Log in to your Contentstack account.
-
Access the settings panel.
-
Choose "Branches" to view a list of existing branches.
2. Select Branch for Deletion:
-
Locate the branch you want to delete from the list.
-
Click on the branch to select it.
3. Delete Branch:
-
Once the branch is selected, look for the option to delete the branch (usually represented by a trash/bin icon).
-
Confirm the deletion when prompted.
Further Reference
Next Up
Article
Comparing Branches
5m 15s