GitHub Branch Protection Rules Essentials Quiz Quiz

Enhance your understanding of branch protection rules within version control workflows. This quiz covers core settings, permissions, and behaviors to help you configure repositories securely and efficiently.

  1. Required Status Checks

    Which branch protection rule prevents merging pull requests unless all required status checks pass, for example, ensuring that automated tests have succeeded?

    1. Required status checks
    2. Enforce admin checks
    3. Linear history enforcement
    4. Signed commits required

    Explanation: Required status checks ensure that specific checks (like automated tests) must complete successfully before merging. Enforce admin checks applies branch rules to administrators but does not enforce status checks themselves. Linear history enforcement mandates no merge commits, unrelated to test requirements. Signed commits required only insists on verified signatures. Only required status checks directly enforce passing checks before merges.

  2. Restricting Force Pushes

    What branch protection setting should you enable to prevent force pushes that could overwrite commit history on a protected branch?

    1. Restrict push access
    2. Require pull request reviews
    3. Disallow force pushes
    4. Allow deletions

    Explanation: Disallow force pushes ensures that no one can force-push changes, which could overwrite commit history. Restrict push access limits who can push, but not specifically force pushes. Require pull request reviews focuses on code review, not push permissions. Allow deletions is unrelated as it controls branch deletion. Disallow force pushes is the correct protection for commit history.

  3. Enforcing Review Requirements

    If you want all changes to a protected branch to be approved by at least one reviewer before merging, which rule should you configure?

    1. Require signed commits
    2. Require pull request reviews
    3. Enforce linear merges
    4. Allow force-push

    Explanation: Require pull request reviews forces code changes to be approved by designated reviewers before merging. Require signed commits only verifies commit signatures, not reviews. Enforce linear merges restricts merge styles, not approvals. Allow force-push is the opposite of what you want, as it can bypass approvals. Thus, requiring pull request reviews is the correct rule for approvals.

  4. Admin Enforcement Option

    How does enabling 'Include administrators' in branch protection rules affect repository admins with respect to those rules?

    1. Admins cannot push to the branch at all
    2. Admins must follow the same rules as everyone else
    3. Admins automatically bypass all rules
    4. Admins receive only notification emails

    Explanation: Selecting 'Include administrators' ensures admins cannot bypass branch protection rules and must comply like other users. Admins are not entirely blocked from pushing; they just have no special bypass privileges. Without this setting, admins could ignore protection rules. Only receiving email notifications does not impact branch protection. The setting makes rules equally strict for everyone.

  5. Deleting Protected Branches

    Which configuration allows deletion of a protected branch even if other protection rules are enabled, for example, when cleaning up old feature branches?

    1. Allow deletions
    2. Require pull request reviews
    3. Disallow force pushes
    4. Require status checks

    Explanation: Allow deletions permits users to delete protected branches despite other branch protection settings. Require pull request reviews only controls merging, not deleting. Disallow force pushes stops overwriting history, not deletion. Require status checks ensures test completion for merges, unrelated to branch deletion. Only allowing deletions provides explicit permission to remove protected branches.