2. Code quality or linting checks
Required status checks in Git - Cheat Sheet & Quick Revision
2. Code quality or linting checks
Practice
What is the main purpose of required status checks in GitHub branch protection?
Solution
Step 1: Understand what required status checks do
They stop merging pull requests if tests or checks fail, ensuring code quality.Step 2: Identify the main goal in branch protection
The goal is to keep the main branch stable by blocking merges that fail checks.Final Answer:
To prevent merging if tests or checks fail -> Option BQuick Check:
Required status checks = prevent bad merges [OK]
- Thinking they delete branches automatically
- Believing they allow direct pushes without review
- Confusing with branch creation features
Which of the following is the correct way to enable required status checks in GitHub?
Settings > Branches > Branch protection rules > Add rule > Require status checks to pass before merging
Solution
Step 1: Locate where branch protection rules are set
Branch protection rules are found under Settings > Branches in GitHub repository.Step 2: Identify the correct path to enable required status checks
Within branch protection rules, you add a rule and select 'Require status checks to pass before merging'.Final Answer:
Settings > Branches > Branch protection rules > Add rule > Require status checks to pass before merging -> Option CQuick Check:
Enable checks via branch protection rules [OK]
- Looking under Actions or Security instead of Branches
- Confusing status checks with pull request reviews
- Selecting unrelated settings paths
Given a branch protection rule with required status checks enabled for ci/test and ci/lint, what happens if a pull request has ci/test passing but ci/lint failing?
Solution
Step 1: Understand required status checks behavior
All required status checks must pass before merging is allowed.Step 2: Analyze the given checks results
Sinceci/lintfailed, the pull request cannot be merged despiteci/testpassing.Final Answer:
The pull request cannot be merged because one required check failed -> Option DQuick Check:
All required checks must pass to merge [OK]
- Assuming one passing check is enough
- Thinking failed checks are ignored
- Believing PR closes automatically on failure
You set required status checks in branch protection, but pull requests are still merging even when checks fail. What is the most likely cause?
Solution
Step 1: Verify branch protection rule settings
Required status checks must be explicitly selected in the branch protection rule to enforce them.Step 2: Understand why PRs merge despite failures
If required checks are not selected, GitHub does not block merges even if checks fail.Final Answer:
Required status checks are not selected in the branch protection rule -> Option AQuick Check:
Check if required checks are enabled in protection rules [OK]
- Assuming checks auto-enable without selection
- Thinking repository branch count affects checks
- Confusing default branch with PR source branch
You want to ensure that pull requests cannot be merged unless both ci/build and ci/test pass, but also want to allow admins to override this if needed. How should you configure the branch protection?
Solution
Step 1: Set required status checks for both
Both checks must be selected to block merges unless both pass.ci/buildandci/testStep 2: Allow admin overrides in branch protection settings
This option lets admins merge even if checks fail, providing flexibility.Final Answer:
Enable required status checks forci/buildandci/test, and allow admin overrides -> Option AQuick Check:
Required checks + admin override = Enable required status checks forci/buildandci/test, and allow admin overrides [OK]
- Selecting only one check instead of both
- Disabling admin override when override is needed
- Confusing pull request reviews with status checks
Ready to prove it?
Pass the test and this pattern moves unknown
