Description
This check verifies that Bitbucket is configured to require changes to be submitted through a Pull Request before they can be merged into protected branches. This control prevents users from bypassing the review process by directly merging changes into critical branches.
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
Requiring Pull Requests ensures that code changes undergo review, discussion, and validation before being merged. This helps improve code quality, supports change management processes, and reduces the risk of introducing unauthorized or untested code into production branches.
Impact
Prevent direct code integration into protected branches.
Require developers to create Pull Requests for all changes.
Increase review and approval activities.
Improve code quality, accountability, and governance.
Default Value
Disabled By default, Bitbucket does not require Pull Requests before changes can be merged. Repository administrators must configure branch restrictions and merge checks to enforce Pull Request-based workflows.
Pre-Requisites
Access to the repository
An existing Bitbucket repository
Test Plan
Sign in to Bitbucket at https://bitbucket.org.
Navigate to Repository Settings.
Select Branch Restrictions.
Review the restrictions configured for the default branch.
Verify that direct pushes are restricted.
Verify that changes must be submitted through Pull Requests before they can be merged.
Create a test change and attempt to push directly to the protected branch.
Implementation Steps
Sign in to Bitbucket at https://bitbucket.org.
Navigate to the target repository.
Select Repository Settings.
Click Branch Restrictions.
Click Add a Branch Restriction.
In the select branch section add * in By branch name or pattern (it will select all branches)
In the write access section, select Only specific people or groups have write access and add users or respective groups, and in the Merge access via pull requests section select Only specific people or groups have merge access and add users or group members.
In the merge check section, enable Minimum number of approvals to 1 or greater than 1
Save the branch restriction.
Backout Plan
Sign in to Bitbucket at https://bitbucket.org.
Navigate to Repository Settings.
Select Branch Restrictions.
Locate the branch restriction configured during implementation.
Remove or modify the restriction.
Save the changes.
Confirm normal repository operations after the rollback.
Reference
https://support.atlassian.com/bitbucket-cloud/docs/use-branch-permissions/
https://support.atlassian.com/bitbucket-cloud/docs/configure-a-projects-branch-restrictions/
https://support.atlassian.com/bitbucket-cloud/docs/work-with-pull-requests/
https://support.atlassian.com/bitbucket-cloud/docs/checks-for-merging-pull-requests/