Design and implement branching strategies for Azure DevOps and GitHub
Learning objectives
- Select a branch model from integration frequency and supported-release needs.
- Configure review, build, merge and bypass controls as separate decisions.
- Evaluate whether the final patch has current verification and independent approval.
- Apply repository controls to agent-authored work without assuming provenance proves quality.
Choose the release model before drawing branches
A branch strategy coordinates integration and maintenance. A continuously deployed service supporting only its current version needs a different arrangement from a product maintaining several released versions. Consider review delay, deployment cadence, integration health and who maintains every supported line.
| Approach | Useful structure | Main boundary |
|---|---|---|
| Trunk-based development | Integrate small changes frequently into a shared main line, using short-lived review branches where policy requires them. | Frequent integration does not remove review or require immediate release of every commit. |
| Feature branches | Isolate one coherent change for review before integration. | Long isolation and unrelated changes increase integration and rollback difficulty. |
| Release branches | Stabilize or maintain selected versions while main continues. | Each line requires testing, ownership and deliberate transfer of applicable fixes. |
| GitHub flow | Branch, commit, push, open a PR, respond to checks/review and merge under policy. | The collaboration flow does not define every production rollout or support arrangement. |
| Original Git flow | Main represents production-ready code; develop integrates future work, supported by feature, release and hotfix branches. | Additional coordination should serve actual versioned-release needs. |
| Git worktree | Use another linked directory for a branch or detached revision in the same repository. | This is a workspace facility, not another release strategy or an independent backup. |
In original Git flow, feature branches leave and return to develop. Release branches begin at develop and ultimately update both main and develop. A production hotfix must also reach the appropriate future release. These relationships are conventions, not special Git object types. Microsoft's main-line release-flow example has its own timed batches; its cadence is not a universal requirement.
For an illustrative frequently shipped service with one supported version, small feature branches and required main-line checks may avoid a permanent develop branch. For two maintained product versions, retain supported release branches and explicitly decide where a security fix must be ported. Do not merge release-specific changes into main indiscriminately.
Separate working context from release policy
If unfinished feature work must remain intact while an urgent fix is investigated, a linked worktree provides another workspace:
git worktree add -b urgent-fix ../urgent-fix
git worktree list
Inspect branch and status in the new directory before editing. For read-oriented inspection of a known commit, use git worktree add --detach ../inspection <commit>. Finish with git worktree remove rather than unexplained directory deletion. Shared repository metadata means the linked directory is not an independent repository backup. A portable or temporarily unavailable worktree can need a worktree lock to prevent stale-metadata pruning; that lock grants no security permission and does not schedule production work. Commands here are documentary examples, not executed repository changes.
Require review of the change that will actually merge
A PR policy must identify the target branch, required reviewers, checks and events that invalidate older evidence. In Azure Repos, the actor needs Edit policies authority. Decide minimum reviewer count, whether the requestor counts, whether the most recent pusher may approve, and how new pushes affect votes. Resetting approvals while retaining reject/wait votes differs from resetting all votes. Requiring the latest iteration's approval differs from counting any old approval. Confirm options against the installed Server version where applicable.
In GitHub, dismissing stale approvals and requiring someone other than the latest pusher to approve the latest reviewable push have different effects. The second need not erase every older review. Required code-owner review is another setting. Give required checks unique job names and, where appropriate, require the expected GitHub App source. Ambiguous names can obscure provenance or block legitimate merges.
Classic GitHub branch protection selects one applicable rule. Do not assume all matching classic patterns accumulate; rulesets have a separate model. Inspect the effective configuration for the actual branch and actor.
Keep build freshness distinct from reviewer independence
Create the selected pipeline before adding Azure Repos build validation. Automatic validation queues at PR creation and source updates; manual validation needs an explicit queue action. Required validation blocks completion when unmet. Optional validation reports without the same blocking guarantee.
Build expiry addresses whether evidence remains current as branches change. Immediate target-change invalidation increases freshness and build cost; a time threshold trades freshness against cost. The following documented distinctions matter:
| Configuration | Freshness implication |
|---|---|
| Never expires | Target/protected-branch updates do not change validation status. |
| Manual + Never | Even a source update can leave the earlier green validation in place. |
| Automatic validation | Source updates always expire the prior validation. |
| Manual validation with the documented source-update expiry arrangement | Select “After n hours if the protected branch has been updated” using the maximum 8,784 hours, or 366 days. Target updates within that duration do not expire the build. |
A person must still queue replacement manual validation and inspect its revision. The maximum-duration arrangement does not change Optional to Required. An independent review of the final patch and a fresh build are separate conditions; satisfying one does not satisfy the other.
GitHub required checks can accept successful, skipped or neutral conclusions. Mergeability therefore does not prove the intended tests executed. Open the actual run, inspect its tested revision, jobs and result, and distinguish deliberately inapplicable checks from missing verification.
For an illustrative final-patch policy, require the actual build, select its freshness behavior, and require independent review of the latest change. After another push, the expected observation is the configured revalidation and review requirement. If a failed Optional build still permits completion, investigate the selected policy rather than calling the configured outcome a malfunction. This lesson specifies expected behavior; it does not report a live test.
Enforce history shape and inspect bypass separately
Azure Repos supports basic/no-fast-forward merge, squash, rebase and fast-forward, and rebase with a merge commit. A basic merge connects histories with a merge commit. Squash records one target commit for the source change, without preserving each source commit separately on target. Rebase replays commits; the selected variant either advances target without a merge commit or adds one afterward. Rewritten commits need care when other people already use their history.
Use Limit merge types to enforce the intended shape. If each accepted PR should become one commit, also allowing ordinary merge does not enforce that objective. Conversely, a topology-preserving policy should not accidentally permit only squash.
Azure Repos distinguishes Bypass policies when completing pull requests from Bypass policies when pushing, the latter covering direct local pushes and web edits. Scope matters: branch exceptions differ from project/repository-wide grants. An unmet policy can remain visibly failed for an actor who may bypass it; the red display alone does not prove enforcement.
GitHub classic protections normally exempt administrators and actors with the relevant bypass unless configured otherwise. Allowed pushers still face required PRs and checks. Enabling force push does not remove linear-history constraints. Branch locking and allowing deletion are different settings. Inspect ruleset-specific bypass rather than transferring classic-rule assumptions.
Verify intended cases separately: a normal writer's direct protected-branch push is blocked, an unapproved PR remains blocked, and an allowed merge method becomes usable after its required evidence exists. An emergency bypass needs a defined scope and expiry; broad permanent exemptions undermine the control.
Apply the same evidence discipline to Copilot work
The adopted GitHub cloud-agent behavior limits work to its existing PR branch when mentioned there, or a new copilot branch otherwise. It cannot approve or merge its PR or mark the draft ready for review. It receives no implied policy bypass.
By default, a write-authorized person reviews the change and approves Actions execution. An optional automatic-workflow setting also exists, so inspect the actual organization setting and entry point before promising unattended execution. Approval to run workflows is separate from approval to merge. The requester of an agent-created PR cannot approve that same request. An unattributed Copilot App PR can require an additional approval when the repository already requires at least one; rulesets can configure that extra requirement, while classic protection follows its documented treatment. Do not convert this conditional behavior into a fixed reviewer count for all agent PRs.
For an illustrative dependency update, inspect the diff before allowing workflow execution, verify the checks at that revision, then obtain the required independent review. Signed commits and session links establish provenance, not security or factual correctness. Issue-driven agents can receive untrusted text; limit their actual tools and writable resources.
Azure Repos through IDE/MCP is a separate route. The adopted inventory supports branch, PR and build context gathering, not a direct branch-policy setter. Use the documented portal or CLI with the authenticated actor's authority. A suggested policy is not a saved policy, and a successful MCP response is not a bypass grant.
Summary
Choose branches to fit release obligations, then enforce current checks, independent review and intended history with their respective controls. Inspect effective actor permissions and bypass rights. Agent-authored work still requires verified inputs and outcomes; provenance, execution approval and merge approval answer different questions.
