Description
This check verifies that deletion of the default branch is restricted in a Bitbucket repository. Branch restrictions help protect critical branches by preventing users from deleting important branches such as main or master, ensuring repository availability and maintaining the integrity of the development workflow.
Note: Only repository-level branch restrictions are detected. Restrictions set only at the project level are not returned by Bitbucket’s API and will result in a FAIL. Configure the restriction at the repository level for accurate results.
Rationale
The default branch typically contains stable or production-ready code. Without branch deletion restrictions, users with repository access may accidentally or intentionally delete the default branch, resulting in disruption to development activities, loss of important source code references, and impact to build or deployment workflows. Restricting deletion of the default branch reduces the risk of unauthorized branch removal and ensures that critical repository branches remain available unless intentionally removed by authorized administrators.
Impact
Prevent accidental deletion of the default branch.
Protect critical source code and repository history from unintended removal.
Reduce the risk of malicious or unauthorized branch deletion.
Require repository administrators to perform controlled branch management activities.
Improve repository governance by ensuring critical branch lifecycle changes are reviewed and authorized.
Default Value
Depends on repository configuration. Bitbucket repositories do not have default branch deletion restrictions enabled automatically. Repository administrators must manually configure branch restrictions to prevent deletion of the default branch.
Pre-Requisites
Repository administrator access
An existing Bitbucket repository
Test Plan
Sign in to Bitbucket at https://bitbucket.org.
Navigate to the target repository.
Select Repository settings.
Under the Workflow section, select Branch restrictions.
Review the configured branch restriction rules.
Verify that a restriction exists for the default branch preventing deletion.
If the default branch does not have deletion protection enabled, follow the implementation steps.
Implementation Steps
Sign in to Bitbucket at https://bitbucket.org.
Navigate to the target repository.
Select Repository settings.
Under the Workflow section, select Branch restrictions.
Click Add a branch restriction.
Select By branch name or pattern and enter the default branch name (for example, main).
Configure the branch restriction to prevent deletion of the default branch.
Ensure the option Allow deleting this branch remains unchecked.
Configure additional branch permissions according to organizational requirements.
Save the changes.
Backout Plan
Sign in to Bitbucket at https://bitbucket.org.
Navigate to the target repository.
Select Repository settings.
Under the Workflow section, select Branch restrictions.
Locate the branch restriction rule configured to prevent deletion of the default branch.
Click Remove to delete the branch restriction rule.
Confirm that repository operations function as expected after the rollback.
Reference
https://support.atlassian.com/bitbucket-cloud/docs/use-branch-permissions/
https://support.atlassian.com/bitbucket-cloud/docs/use-branch-permissions/
https://support.atlassian.com/bitbucket-cloud/docs/work-with-pull-requests/