main, release/*, and others from accidental or unauthorized changes.
Overview
Branch protection allows you to:- Block direct pushes (require pull requests)
- Prevent force pushes
- Block branch deletion
- Require code reviews
- Enforce status checks
- Restrict who can push
Quick Start
Commands
List Rules
Add a Rule
Update a Rule
Remove a Rule
Show Rule Details
Check Operations
Verify if an operation would be allowed:Protection Status
See a summary of protection for a branch:Options
Push Restrictions
| Option | Description |
|---|---|
--require-pr | Block direct pushes, require pull requests |
--no-require-pr | Allow direct pushes |
--no-force-push | Block force pushes |
--allow-force-push | Allow force pushes |
--no-delete | Block branch deletion |
--allow-delete | Allow branch deletion |
--restrict-push | Restrict who can push |
--allowed-pushers <users> | Comma-separated list of allowed users |
Review Requirements
| Option | Description |
|---|---|
--approvals <n> | Number of required approvals (0-10) |
--dismiss-stale | Dismiss approvals when new commits are pushed |
--require-codeowner | Require review from code owners |
Status Checks
| Option | Description |
|---|---|
--status-checks <checks> | Comma-separated list of required checks |
--require-up-to-date | Require branch to be up-to-date before merge |
Metadata
| Option | Description |
|---|---|
--description <text> | Description for the rule |
--preset <name> | Use a preset (basic, standard, strict) |
Presets
wit includes built-in presets for common protection scenarios:Basic
- Blocks force push
- Blocks deletion
- Allows direct push
Standard
- Requires pull request
- Requires 1 approval
- Dismisses stale reviews
- Blocks force push
- Blocks deletion
Strict
- Requires pull request
- Requires 2 approvals
- Dismisses stale reviews
- Requires code owner review
- Requires status checks
- Requires branch up-to-date
- Blocks force push
- Blocks deletion
Pattern Matching
Protection rules support glob-style patterns:| Pattern | Matches |
|---|---|
main | Exact match |
release/* | release/1.0, release/2.0 |
feature/** | feature/foo, feature/foo/bar |
*/protected | team/protected, user/protected |
Storage
Branch protection rules are stored in.wit/branch-protection.json: