What is branch protection?
BeginnerConceptBranching, versioning & releases
Answer
In one line: Branch protection is a set of rules on important branches (like main) that stop people from pushing directly, deleting the branch or merging without the required reviews and passing checks.
Common branch protection rules (GitHub, GitLab, Azure Repos, Bitbucket):
- Require a pull request — no direct pushes to main.
- Required approvals — for example at least 1 or 2 reviewers.
- Code owner review — changes to certain paths need approval from their owners (
CODEOWNERS). - Required status checks — CI must pass (build, tests, security scans) before merging.
- Branch must be up to date with main before merging.
- Dismiss stale approvals when new commits are pushed.
- Require signed commits (verified authorship).
- Linear history — only squash or rebase merges.
- Block force pushes and deletion.
- Apply rules to admins too — no bypassing.
Example CODEOWNERS file:
/terraform/ @org/platform-team
/.github/workflows/ @org/devops
*.sql @org/dba-team
Why it matters in DevOps:
- Keeps main always releasable — nothing untested gets in.
- Enforces peer review — a lightweight, effective replacement for heavy change boards.
- Gives an audit trail of who approved each change, which auditors like.
- Protects against accidents and compromised accounts (no force-push wiping history).
Tip for interviews: list a few rules you've configured, and mention CODEOWNERS for infrastructure and pipeline files.
More on Branching, versioning & releases
What is a branching strategy, and why does it matter?BeginnerWhat is trunk-based development?BeginnerWhat is GitFlow, and when would you use it?BeginnerWhat is semantic versioning?BeginnerWhat is a Git tag, and how are tags used in releases?BeginnerWhat is a pull request, and what makes a good code review?Beginner