Branching strategies and pull requests

AZ-400 DevOps EngineerSource control strategyAbout 20 minutesBy Cloud Hands On

Trunk-based, feature and release branches, pull request workflows, branch policies and protection rules, and merge restrictions.

In this lesson you'll learn

1. Branch strategies

New to branching? Start here

A branch is a separate line of work. You make changes on a branch without affecting main, then bring them back through a pull request. The question is how many branches you keep and for how long.

StrategyHow it worksSuits
Trunk-basedEveryone merges small changes into main often (at least daily); short-lived branches; unfinished work hidden behind feature flagsContinuous delivery, frequent releases
Feature branchOne branch per feature, merged through a pull request when doneMost teams; easy reviews
Release branchCut release/2.4 from main when stabilising a version; fixes go to main and are cherry-pickedProducts supporting several versions

Long-lived branches cause painful merges. Keep branches short, and make main always releasable.

2. Pull request workflow

A pull request is where code meets review and automation. A good workflow requires: a minimum number of reviewers, required reviewers for sensitive paths (code owners), a passing build (status check), resolved comments, and linked work items.

  • Azure Repos branch policies: require a minimum number of reviewers, check for linked work items, check for comment resolution, limit merge types, build validation, status checks, and automatically included reviewers by path.
  • GitHub branch protection rules and rulesets: require pull request reviews, required status checks, code owner review, signed commits, linear history, and restrict who can push. Rulesets can apply to many branches and repositories at once.

3. Merge types and restrictions

  • Merge commit: keeps every commit and adds a merge commit.
  • Squash merge: combines the pull request into one commit: a clean, linear history.
  • Rebase and fast-forward: replays commits on top of the target, linear without a merge commit.
  • Semi-linear merge (Azure Repos): rebase, then a merge commit.

Both platforms let you limit the merge types allowed, and stop people pushing directly to protected branches, so every change goes through a pull request. In Azure Repos, direct pushes are blocked once a branch has a required policy; you can grant Bypass policies permission to a small group for emergencies.

Example

Ironbridge Payments uses trunk-based development. main requires two reviewers, a code owner for the payments folder, a green build and squash merges only. Features that aren't ready ship behind flags, so main is released several times a day.

Exam traps to remember

  • Build validation is the Azure Repos policy that runs a pipeline on each pull request.
  • Squash merge gives one commit per pull request; rebase keeps each commit but no merge commit.
  • Trunk-based development relies on feature flags to hide unfinished work.

Test yourself: 3 check questions and exam-style practice questions on this topic are in the AZ-400 DevOps Engineer app.

Practise in the app

Keep going