CodeBlanks Logo Icon CodeBlanks

Summary - Branch protection

Combine protection rules to secure the main branch.

Combining Branch Protection Rules

A reliable main branch protection setup is created by applying multiple rules together. Requiring pull requests restricts direct changes; the review policy requires team approval; and status checks require automated tests to succeed. Together, these rules make it harder for faulty or unreviewed changes to reach the main branch.

main:
  require_pull_request: true
  required_approvals: 2
  required_status_checks:
    contexts:
      - test

Each rule provides a different layer of protection in the development process.

Practice Protect the Main Branch with Multiple Rules

Complete the protection settings for the main branch. Enable required pull requests, require at least two approvals, and set strict: true under required_status_checks. Finally, add the test check to the contexts list.

Starter code

terminal
# Pull request zorunluluğu
# İnceleme onay sayısı
# Otomatik kontroller

Sample solution

terminal
main:
  require_pull_request: true
  required_approvals: 2
  required_status_checks:
    strict: true
    contexts:
      - test

Expected output

Ana dal için tüm koruma kuralları etkinleştirildi.

Questions and answers

Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.

1 Which two rules should be combined when both team approval and successful automated tests are required before a change reaches the main branch?

  • Commit message and repository description
  • Stash and file history
  • Required review and required status checks Correct answer
  • Branch deletion and tag creation

Explanation: Required reviews provide team approval, while required status checks ensure that automated checks succeed.

2 Set the Approval Count for the Main Branch

Question
main:
  require_pull_request: true
  ____: 2
Answer
main:
  require_pull_request: true
  required_approvals: 2

Explanation: When <code>required_approvals</code> is set to 2, at least two approvals are required before merging.

3 Protection Layers

Term Meaning
Pull request zorunluluğu Routes changes through review
Required review Requires team approval
Status check Validates automated tests
Dal koruma politikası Enforces rules together

All lessons in Advanced