What is branch protection on GitHub, and what rules can you set?
Branch protection rules guard important branches like main. You can require pull requests, a number of approvals, passing status checks, up-to-date branches, and block force pushes and deletion.
Explain it simply
Branch protection is a lock on the main gate: nobody walks in directly, not even the senior developer on a busy day.
Under Settings, Branches, you add a rule for main. Typical options: require a pull request before merging, require one or two approvals, require status checks like tests to pass, require conversations resolved, require linear history, and block force pushes. You can apply rules to administrators too. This ensures every change is reviewed and tested before reaching production.
Example
Rule for: main
[x] Require a pull request before merging (1 approval)
[x] Require status checks to pass: tests, lint
[x] Block force pushes
[x] Do not allow deletionWhat to say in the interview
"Branch protection enforces rules on a branch such as main: required pull requests and approvals, passing status checks, no force pushes or deletion. It guarantees that nothing reaches main without review and green tests."