GH-900 ยท Security and administration
Branch protection rules
Required reviews, required status checks, restricting force pushes and deletions on important branches, and how rulesets relate.
Key points
- Branch protection guards important branches such as main.
- You can require pull request reviews (a set number of approvals, optionally from code owners), require status checks to pass before merging, block force pushes and deletions, and require linear history or signed commits.
- Only one branch protection rule applies to a branch at a time, while rulesets are the newer, layered alternative that can be combined.
Practice questions
Which branch protection option makes sure automated tests succeed before a pull request can be merged?
- Require status checks to pass
- Block force pushes
- Require signed commits
- Restrict deletions
Show answer
Answer: A. Require status checks to pass
Required status checks block merging until the named checks pass. Required reviews involve human approval, and blocking force pushes protects history.
Which protections can be applied to an important branch?
- Require approving reviews on pull requests
- Require status checks to pass before merging
- Restrict force pushes
- Automatically translate the README
- Require an emoji in every commit message
Show answer
Answer: A. Require approving reviews on pull requests, B. Require status checks to pass before merging, C. Restrict force pushes
Required reviews, required status checks and blocking force pushes are all branch protection options. Automatically translating the README and mandatory emoji commits are not.
True or false: by default, admins and roles with the bypass permission are always subject to branch protection rules.
Show answer
Answer: False
False. Admins can bypass by default; the option to not allow bypassing must be enabled for the rules to apply to them too.
Practice 8 questions on this topic in Bitzu
Short lessons, instant explanations and spaced review of what you get wrong. Free on iOS and Android.
