Branch protection keeps critical branches — like main or production — safe from accidental or unreviewed changes.
Enable branch protection
- Open your project’s Settings → Branches page.
- Add a rule for a branch (for example,
main). - Choose what to enforce.
Options
- Prevent direct pushes — changes to the branch must come through a pull request.
- Require reviewers — a pull request needs approvals before it can be merged.
- Require status checks — builds must pass before merging (available with CI/CD enabled).
How it feels in practice
With protection on, git push origin main is rejected with a helpful message. Instead, you open a pull request, get it reviewed and approved, and merge — keeping your history clean and your main branch shippable.