Protected branches
Lock the default branch against direct edits and pushes.
1. Open repository settings
Navigate to
/{owner}/{repo}/settings(maintainer access required). Org admins see additional controls.2. Find Branch protection
The Branch protection section explains that the default branch is protected from direct pushes and browser edits when enabled.
3. Toggle protection
Click Enable protection or Disable protection. A success message confirms Branch protection updated.
4. Require status checks before merge
On the Branches tab, maintainers can check Require status checks next to any branch. When enabled, all automated build, test, and security checks reported on the source branch tip via
POST /api/v1/:owner/:repo/commits/:commitId/statuses(pending,success,failure,error) must besuccessbefore a pull request can be merged. The pull request page displays each check and disables Merge pull request with a clear explanation while any check is missing, pending, or failing.5. Require review before merge
On the Branches tab, maintainers can check Require review to merge next to any branch. When enabled, pull requests targeting that branch cannot be merged until at least one Approve review exists with no outstanding Request changes. A direct merge from the Branches page is rejected. A CLI push to a protected branch fails with: Branch is protected — direct writes not allowed.
6. Work on a feature branch
With protection on, create a branch under Branches, commit there, compare, then merge into the default branch.
