Cyber Intelligence
Source Control Strategy · 10-15% of exam

L5. Pull Request Workflows: Branch Policies & Protection Rules

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)
  • Automatic reviewer suggestion based on a CODEOWNERS file

Once configured, a PR cannot merge until all 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, only rebase)
  • 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 PR touches files, GitHub (and similar systems) automatically request review from the designated owner:

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

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

Here is the exam trap: branch policies and protection rules do not automatically apply to repository administrators unless the setting explicitly includes admins in enforcement. This is a security misconfiguration that appears frequently on the AZ-400 exam.

A team sets up "require 2 reviewers and passing build" but forgets to enable "enforce for administrators." An admin can then bypass both requirements and merge directly to main, defeating the entire policy.

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
Exam tip: The AZ-400 exam often tests the admin bypass misconfiguration and the relationship between build validation policies and protecting merge results (not just source branches).

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
  • Branch policies and protection rules do not automatically apply to repository administrators unless the configuration explicitly includes admins in enforcement, a common misconfiguration that lets an admin bypass required checks
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?

Recommended: Pluralsight

This free course covers the theory. Pluralsight adds structured DevOps Engineer Expert learning paths, hands-on Azure Pipelines and GitHub Actions labs, and timed practice exams to make it stick before exam day.

Start AZ-400 prep free10-day free trial available