Secure Your Production Code with Bitbucket Cloud Branch Permissions
Learn how to use Bitbucket Cloud’s Branch Permissions to lock critical branches, enforce reviewers and CI checks, and keep production code safe. Follow a step‑by‑step guide, see an API example, and understand trade‑offs.
24 Sept 2026, 02:44 UTC

Why Branch Permissions Matter
In a fast‑moving team, the temptation to push directly to main or a release branch can lead to accidental regressions. Bitbucket Cloud’s Branch Permissions let you lock down who can write to, delete, or merge into specific branches, ensuring that only vetted code reaches production.
Setting Up a Basic Protection Rule
- Navigate to the repository you own or administer.
- Click Repository settings → Branch permissions in the left‑hand menu.
- Press Add a branch permission and choose Write access (or Delete if you want to lock deletion).
- In the Branch name pattern field, enter
main(orrelease/*for all release branches). - Under Require reviewers, set the minimum number of approvals (e.g., 1).
- Optionally, enable Require a successful build to enforce CI checks before merging.
- Click Save.
After saving, any push to main from a non‑admin account will be rejected. Pull requests will be blocked until the required reviewers approve and the pipeline passes.
API‑Based Example
For automation, you can create a permission rule via the REST API. Replace <repo-id> and <workspace> with your values.
curl -X POST \
https://api.bitbucket.org/2.0/repositories/<workspace>/<repo-id>/branch-restrictions \
-u <username>:<app-password> \
-H "Content-Type: application/json" \
-d '{
"kind": "write",
"pattern": "main",
"users": [""],
"approvals": 1,
"builds": {"required": true}
}'}
Note: the API requires an app password with the repository:write scope.
How It Works With Pipelines
Bitbucket Cloud integrates branch permissions with Pipelines. When a pull request targets a protected branch, the merge button remains disabled until:
- The pipeline finishes successfully.
- All required reviewers have approved.
- Any additional merge checks (e.g., no conflicts) pass.
Result: broken code never lands in production, and reviewers are forced to validate changes.
Trade‑Offs and Gotchas
| Consideration | Impact |
|---|---|
| Over‑restrictive rules | Can stall feature releases if the rule blocks legitimate contributors. |
| Admin override | Repository admins can bypass the rule; document rules for audit. |
| Tagging & PR creation | Branch permissions do not affect tags or creating pull requests; add separate settings if needed. |
| Bitbucket Server | Feature is only in Bitbucket Cloud; Server uses a different permission model. |
Actionable Checklist
- Create a test rule on a non‑critical branch (e.g.,
dev-test) to verify behavior. - Apply the rule to
mainor your release branches once you’re confident. - Document the rule set in your repo’s
READMEor a dedicatedSECURITY.md. - Periodically review the list of admins who can override rules.
- Combine branch permissions with required reviewers and CI checks for maximum safety.
By following these steps, you can protect critical branches while maintaining a healthy CI/CD workflow.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.