Design a branch strategy, including trunk-based, feature branch, and release branch
Evaluate Branching Models within Azure Repos
In Azure Repos, teams choose a branching strategy to manage how code is written and integrated. The three main models are trunk-based development, feature branch development, and release branch development. The choice depends on team size, how often you release software, and your level of testing automation. Each model affects how developers collaborate and how quickly you can deliver updates.
Trunk-Based Development
With trunk-based development, all developers commit their code directly to a single central branch, usually called main. This approach encourages frequent integration, often multiple times a day, which helps avoid large, difficult merge conflicts. However, because everyone works on the same branch, this model relies heavily on automated testing to catch bugs right away. Teams must use strong continuous integration (CI) pipelines to check every commit and keep the main code stable.
Feature Branch Development
The feature branch model isolates new work by having developers create a temporary branch for each new feature or bug fix. Developers can write and test their code in this isolated space without affecting the main branch or other team members. When the work is done, they submit a pull request to merge the changes back into main. This workflow creates a clear checkpoint for code reviews, allowing the team to discuss and approve changes before they become part of the shared codebase.
Release Branch Development
Teams use a release branch strategy when they need to support multiple live versions or require a dedicated stabilization phase before deployment. A release branch is created from the main branch when the software is nearly ready to ship. This isolates the release from ongoing feature development. Critical bug fixes can be applied directly to this release branch without stopping new work in main. This separation ensures a stable deployment environment and makes it easier to manage different versions over time.
Branch Policies and Best Practices
To protect the codebase, administrators set up branch policies in Azure Repos. These policies act as quality gates, enforcing rules like requiring a minimum number of reviewers for a pull request or demanding that all code passes automated build checks before a merge. Teams should also use clear naming conventions to keep the repository organized. By combining these policies with automated CI/CD pipelines, teams can run security checks, execute tests, and deliver updates with less manual work.
Design and implement a pull request workflow by using branch policies and branch protections
Enforce Branch Policy Requirements
Branch policies are rules in Azure DevOps that ensure code quality and secure workflows when merging changes through pull requests. They act as quality gates that block a merge until every condition is met, protecting important branches from unauthorized or low-quality code. These policies automate consistent standards so teams don't have to rely on manual checks.
A policy can require a minimum number of reviewers to approve a pull request before it merges. It can also enforce required successful builds, meaning the automated build pipeline must pass first. Merge strategies control how the code is integrated, such as using a squash to combine commits or a rebase to reapply commits on top of the target branch. Additional settings can block unresolved comments or require linked work items to improve traceability. Path filters let the policy apply only to specific folders or file types, which is useful for applying different rules to different parts of the code.
Implement branch merging restrictions by using branch policies and branch protections
Branch policies are rules you set on important branches, like your main branch, to control how code is merged. They act as a quality gate, ensuring every change meets your team's standards before it joins the official codebase.
Implement Branch Policies
You can create several key policies. A minimum reviewers policy requires a set number of team members to approve a pull request, which helps spread knowledge and catch errors. A successful build validation policy forces the code to pass automated builds and tests in your pipeline, preventing broken code from being added. You can also define specific merge strategies, like requiring a squash merge, to keep the branch history clean.
Enforce Branch Protections
Beyond policies, you can lock a branch down with protections. These settings stop people from bypassing your rules. Key protections include blocking force pushes, which prevents someone from overwriting the branch's commit history, and blocking direct commits, which ensures every change must come through a reviewed pull request. This keeps the branch's history reliable and forces all work through your approved process.