# Branch Protection

> Rules that keep changes off a branch until reviews and tests pass.

**Field:** Software Development  
**Category:** Version Control  
**Also known as:** Protected Branch, Branch Protection Rule, Branch Ruleset

## Think of it like

Think of it like a lock on the front door. Only guests who pass the checks get in.

## Definition

Branch protection is a set of rules a code host puts on a branch, usually main. It can require a pull request before anything is merged. It can require an approving review and passing tests. On GitHub, it blocks force pushes and deleting the branch by default. Nobody can then push broken code to main by mistake.

## Example

Emma locks main on GitHub. Now each pull request needs one approval and passing tests before it can merge.

## Why it matters

It turns good habits into rules the code host enforces.

## Common mistake

Letting admins skip the rules. Then the one rushed fix that breaks main gets through.

## Three principles

- **Gate the branch.** Changes come only through checks.
- **Reviews and tests.** Both must pass before merge.
- **No force push.** History on main cannot be rewritten.

## Related terms

- [Main Branch](https://learn.benibix.com/term/development/main-branch)
- [Pull Request](https://learn.benibix.com/term/development/pull-request)
- [Code Review](https://learn.benibix.com/term/development/code-review)
- [Continuous Integration (CI)](https://learn.benibix.com/term/development/continuous-integration)
- [GitHub](https://learn.benibix.com/term/development/github)

## Told apart from

- [Git Hook vs Branch Protection](https://learn.benibix.com/compare/git-hook-vs-branch-protection): People think a pre-commit hook keeps bad code off main, and it does not. A Git hook runs on one person's computer. A clone does not copy it, and git commit --no-verify skips it. Branch protection runs on the Git host. It locks main until reviews and tests pass, and nobody can skip it unless they are allowed to.

## Taught in

- [Branch Protection and Hooks](https://learn.benibix.com/learn/development-version-control/branch-protection-and-hooks): Git and GitHub, 12/13

![A pull request flows from a feature branch toward a protected main branch drawn with a lock. On the way it must pass two gates: one review approved, and all tests passed. Beside the flow, an issue numbered 42 is linked, with the words Closes #42, and it closes when the merge lands. Below, three hosts that run this flow are named: GitHub, GitLab and Bitbucket.](https://learn.benibix.com/diagrams/dev3-git-hosting.svg)

---

Source: https://learn.benibix.com/term/development/branch-protection
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-17
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
