0
0
Gitdevops~20 mins

Branch protection rules in Git - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Branch Protection Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1:30remaining
What is the primary purpose of branch protection rules?

Branch protection rules in Git repositories help teams maintain code quality and control. What is the main goal of these rules?

ATo allow anyone to force push changes anytime
BTo automatically merge all pull requests without review
CTo delete branches after every commit
DTo prevent direct pushes to important branches without review or checks
Attempts:
2 left
💡 Hint

Think about how teams avoid mistakes on main branches.

💻 Command Output
intermediate
2:00remaining
What is the output of listing branch protection rules with GitHub CLI?

Using GitHub CLI, you run the command to list branch protection rules for the 'main' branch. What output do you expect?

Git
gh api repos/owner/repo/branches/main/protection
A{"required_status_checks":{"strict":true,"contexts":["ci/test"]},"enforce_admins":true,"required_pull_request_reviews":{"required_approving_review_count":2}}
BError: branch 'main' not found
CPermission denied: cannot access branch protection
DNo protection rules set for branch 'main'
Attempts:
2 left
💡 Hint

Think about what a successful API call returns.

Configuration
advanced
2:30remaining
Which YAML snippet correctly enforces branch protection in GitHub Actions workflow?

You want to enforce that pull requests to 'main' must pass tests before merging. Which YAML snippet correctly configures this?

A
on:
  pull_request:
    branches-ignore:
      - main
jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - run: echo "Run tests here"
B
on:
  push:
    branches:
      - main
jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - run: echo "Run tests here"
C
on:
  pull_request:
    branches:
      - main
jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - run: echo "Run tests here"
D
on:
  pull_request:
    branches:
      - develop
jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - run: echo "Run tests here"
Attempts:
2 left
💡 Hint

Which event triggers the workflow for pull requests targeting 'main'?

Troubleshoot
advanced
1:30remaining
Why does a force push to a protected branch fail?

You try to force push changes to a protected branch but get an error. What is the most likely reason?

AYour local Git client is outdated and cannot push
BBranch protection rules disallow force pushes to prevent overwriting history
CThe remote repository is full and cannot accept new commits
DYou forgot to pull the latest changes before pushing
Attempts:
2 left
💡 Hint

Think about why force pushing might be blocked on important branches.

🔀 Workflow
expert
3:00remaining
In what order should these steps be configured to enforce branch protection with required reviews and status checks?

Arrange the steps to correctly set up branch protection rules that require pull request reviews and passing status checks before merging.

A3,2,1,4
B2,3,1,4
C1,3,2,4
D3,1,2,4
Attempts:
2 left
💡 Hint

Think about selecting the branch first, then defining checks and reviews, then saving.