Branch protection
A protected branch cannot be deleted or rewritten with a force push unless the section's rules allow it, and with the «Require a pull request» rule changes reach it only by merging a pull request.
In this article
Turn it on#
- Settings → Branch protection.
- Pick a branch and press Protect. The default branch is always protected. If there is no branch with that name yet, the protection applies once it appears.
What changes#
- The branch cannot be deleted — neither from the site nor with
git push --delete— unless Allow deletions is on. - A force push to it is rejected: the history of a protected branch cannot be rewritten unless
Allow force pushes is on. Force pushes to unprotected branches are always allowed — for
example, after a
rebaseof your working branch.
Allow force pushes and deletions#
Two checkboxes in the same section relax the protection, like the rules of the same name in GitHub branch protection:
- Allow force pushes — protected branches, including the default one, accept
git push --force. Rewritten commits become unreachable and cannot be recovered — turn it on only when you really rewrite history, and turn it off afterwards. - Allow deletions — protected branches on the list can be deleted by a push and with the button on the site. Nothing deletes the default branch: change the default branch first.
Require a pull request#
The Require a pull request checkbox in the same section closes protected branches to direct changes:
git pushto the branch is rejected with «accepts changes only through a pull request»;- a file cannot be saved or deleted in the browser directly in that branch;
- a branch cannot be merged into it with a button, bypassing a pull request.
Changes reach the branch by merging a pull request, where reviews and checks apply. When the settings require approvals or code owner reviews, the checkbox turns on by itself — otherwise approvals could be bypassed by a direct push.
The checkboxes are saved as soon as you change them.
Remove it#
Each branch in the same list has Lift protection; the checkboxes are cleared separately. The changes go into the audit log.
Was this helpful?