How to protect a branch on GitHub
On GitHub (verified 2026-10-24), open the repository → Settings → Rules → Rulesets (or classic Branches → Add branch protection rule). Target main (or your default branch). Enable Require a pull request before merging, set required approvals, optionally Require status checks to pass, and disallow force pushes. Save the ruleset/rule.
Classic branch protection and newer repository rulesets both exist — orgs may standardize on rulesets. Admins can still bypass unless you limit bypass actors. Protection does not replace CODEOWNERS; combine them for clearer review routes.
Applies to GitHub.com repositories where you have admin permission. Organization rulesets can enforce defaults above the repo. UI labels differ slightly between classic branch protection and rulesets.
Create a protection rule for the default branch
Open branch rules
- Repo → Settings.
- Open Rules → Rulesets (or Branches for classic protection).
- Click New ruleset / Add branch protection rule.
Target the branch
- Name the ruleset (e.g. Protect main).
- Include the branch
main(or your default branch pattern). - Set enforcement to Active when you are ready.
Require reviews and checks
- Enable require pull request before merging + approval count.
- Optional: require status checks / conversation resolution.
- Block force pushes and deletions → save save the ruleset.
Our take: protect main on day one
Even solo repos benefit — future you (and CI) will thank you when a bad push cannot skip reviews.
If it fails
- Settings missing: you are not an admin, or the org locked repo settings.
- PRs blocked with no checks: you required a status check that never reports — fix the check name or remove it.
- Admin bypass confusion: restrict bypass actors if even admins should PR.
- Ruleset vs classic: do not stack conflicting classic rules and rulesets — pick one model.
Frequently asked questions
How do I protect main on GitHub?
Settings → Rulesets (or Branches) → add a rule targeting main → require PRs/reviews → save.
What does branch protection do?
It blocks direct pushes (when configured), force-pushes and merges that skip required reviews or checks.
Do I need GitHub Pro?
Public repos have broad protection features; private-repo capabilities can depend on plan — check current GitHub docs for your account type.
Rulesets vs classic branch protection?
Rulesets are the newer flexible model; classic branch protection still works on many repos — orgs may require rulesets.
Can I require CI to pass?
Yes — require status checks and select the check names your workflows report.