# 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.

> **Who can use this:** The repository owner.

## Turn it on

1. **Settings → Branch protection**.
2. 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 `rebase` of 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 push` to 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](https://skillok.org/docs/en/issues-and-pulls/pull-requests), 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.

---

https://skillok.org/docs/en/repositories/settings/branch-protection
