Protego field desk
Source Control Strategy · 10-15% of exam

L5. Pull Request Workflows: Branch Policies & Protection Rules

Course outlineLesson 5 of 18

Build validation policies, CODEOWNERS-driven review routing, and the common misconfiguration that lets repository administrators bypass required checks entirely.

Branch Policies and Protection Rules

Every modern source control system lets you enforce rules on which code can merge to a protected branch. Azure Repos calls these branch policies. GitHub calls them branch protection rules. They serve the same purpose: preventing code from reaching main (or another critical branch) without meeting quality gates.

Azure Repos Branch Policies

Azure Repos branch policies can enforce:

  • Minimum number of reviewers (1, 2, or more)
  • Linked work items required (every PR must reference a work item)
  • Successful build validation (a specific pipeline must pass)
  • Comment resolution required (all PR comments must be resolved before merge)
  • Blocking direct pushes (enforces code review via PR, no bypassing)
  • Automatically included reviewers configured with path filters in Azure Repos branch policies

With required policies configured and bypass permissions restricted, a PR cannot merge until the required policies pass. Policies are configured per branch pattern, so you might require 2 reviewers for main but 1 reviewer for develop.

GitHub Branch Protection Rules

GitHub branch protection rules offer similar enforcement:

  • Required pull request reviews (minimum number)
  • Required status checks (specific build, test, or security pipelines)
  • Dismiss stale PR approvals when new commits are pushed
  • Require signed commits (cryptographic verification of commit identity)
  • Require linear history (no merge commits; use squash or rebase merges)
  • Restrict push and merge permissions to specific users or teams

Build Validation: The Critical Policy

Build validation ties a specific pipeline to a branch policy. When you set up build validation, the policy does not just run the pipeline on the PR source branch; it runs the pipeline on the merge result (source branch merged into target). This is crucial because it tests whether the code works when merged, not just in isolation.

If build validation is missing, a PR could pass all tests in isolation but break the build after merging to main because of conflicts or incompatibilities with main's current state.

CODEOWNERS: Automatic Reviewer Assignment

A CODEOWNERS file maps file paths to owners. When a non-draft PR touches owned files, GitHub automatically requests review from the designated owner:

# Example CODEOWNERS file
/src/auth/*         @example-org/security-team
/docs/*             @example-org/tech-writer
/infra/terraform/*  @example-org/platform-team

Replace example-org with your organization and use teams with explicit repository write access. Require code-owner review in branch protection if their approval must block merging. This removes the manual step of figuring out who should review. The system routes PRs to the right people based on what changed.

The Admin Bypass Trap

GitHub branch protection excludes administrators and custom roles with bypass permission by default. Enable Do not allow bypassing the above settings to include them. Azure Repos controls bypass separately with Bypass policies when completing pull requests and Bypass policies when pushing permissions. Audit these permissions rather than assuming a GitHub setting controls Azure Repos.

Merge Strategies

The way code merges affects history. Common strategies include:

StrategyHistoryProsCons
Merge CommitFull history preservedSee every PR and integrationHistory becomes complex fast
Squash MergeSingle commit per PRClean, linear historyLoses individual commit details
Rebase MergeLinear history, no merge commitClean and simpleRewrites commit hashes
Review tip: Check bypass permissions and validate proposed merge results, rather than testing only source branches.

References

Continue Learning

Exam Focus Points
  • ✓Azure Repos branch policies can require minimum reviewers, linked work items, successful build validation, and comment resolution before a pull request can merge
  • ✓GitHub branch protection rules can require passing status checks, required reviews, signed commits, and linear history before allowing a merge into a protected branch
  • ✓A build validation policy ties a specific pipeline to a branch, so the PR cannot merge until that pipeline succeeds against the proposed merge result, not just the source branch alone
  • ✓A CODEOWNERS file automatically requests review from the right people or team based on which files a pull request touches
  • ✓GitHub protection excludes admins by default unless bypass is disabled; Azure Repos uses separate bypass permissions for PR completion and pushing
Knowledge Check

1. A team wants to guarantee that a pull request cannot merge into main unless a specific build pipeline succeeds against the exact code that would result from the merge. What should they configure?

2. What does a CODEOWNERS file accomplish in a pull request workflow?

3. A security team configures branch protection requiring passing status checks and two reviewer approvals on main, but discovers a repository administrator was able to merge without either. Why did this happen?