Protecting Main
Rules GitHub enforces.
Rules work best when nobody can break them by accident. GitHub lets you protect a branch, usually main, with rules it enforces automatically.

- Rules can be broken by accident
- GitHub can enforce them
- Protect the main branch
Common protection rules
In the repository settings, under branches, or rules, you can require a pull request before merging, so nobody pushes straight to main. Require at least one approval. Require automatic checks, like tests, to pass. And block force pushes, so history on main can never be rewritten.
Without and with protection
Without protection, anyone with access can push straight to main, or even force push, and break things for everyone. With protection, GitHub rejects direct pushes to main. Every change has to arrive through a reviewed pull request, with its checks passing. Mistakes get caught before they reach main.
Unprotected main
- Direct pushes allowed
- Force pushes allowed
- Mistakes reach main
Protected main
- Pull requests only
- Reviews and checks required
- Mistakes caught early
Summary
Branch protection makes GitHub enforce your rules. Pull requests, approvals, passing checks, and no force pushes. Next, a few habits that make a team work smoothly.
Key takeaways- Settings, branches or rules
- Require PRs and approvals
- Block force pushes