AZ-401 Domain 2: Design and implement a source control strategy
10–15% of the exam (AZ-400: 10–15%). 10 skills in 2 tasks, 3 of them new in AZ-401. Study notes for each task below, then 5 free questions with answers.
35 Domain 2 questions in the bank, 5 free. Answer them one at a time with explanations.
Practice Domain 2Skill wording is quoted from the official study guide. Tags compare each skill with the AZ-400 guide.
2.1 Design and implement branching strategies for Azure DevOps and GitHub
Task 2.1 covers choosing a branching model, including Git worktrees for parallel human and agent work, and enforcing it with Azure Repos branch policies and GitHub rulesets or branch protection, now with rules that apply to Copilot. Questions hinge on the exact option: who can approve, when a build expires, which merge type, and who can bypass.
- 2.1.1Design a branch strategy, including trunk-based, feature branch, release branch, Git Worktree, Git flow, and GitHub flow 4 questions
- 2.1.2Design and implement pull request workflows by using branch policies and branch protection rules 4 questions
- 2.1.3Implement branch merging restrictions by using branch policies and branch protection rules 3 questions
- 2.1.4Implement branch policies and branch protection rules for GitHub Copilot New in AZ-4016 questions
Which branching strategy fits which release model?
main: short-lived branch, pull request with review and checks, merge, deploy. It has the lowest overhead and fits continuous deployment of a single production version. Microsoft describes GitHub flow as trunk-based development; trunk-based teams commit to short-lived topic branches off one main branch and hide unfinished work behind feature flags instead of long-running feature branches. Git flow adds a long-lived develop branch plus release and hotfix branches; it suits scheduled, versioned releases. Release branches suit release cycles with a stabilization phase. In Microsoft's release flow, a release branch such as releases/M129 is cut from main and never merged back. A hotfix goes into main first through a PR, then is cherry-picked into a new PR that targets the release branch, so both get the same policies and the bug can't return when the next release is cut. Forking suits outside contributors who shouldn't have write access.Source: How Microsoft develops with DevOps; GitHub flow
When does Git worktree beat a second clone or a stash, especially for parallel agents?
git worktree add creates a linked working tree in another folder that shares the repository's objects and refs; only per-worktree files such as HEAD and the index are separate. git worktree add -b hotfix/4.2.1 ../hotfix origin/release/4.2 creates and checks out a hotfix branch while your uncommitted work stays untouched, with nothing stashed and nothing downloaded again. Remove the worktree when the fix is done. A new worktree starts from committed content, so uncommitted, untracked and git-ignored files (installed dependencies, local config) aren't in it. By default Git refuses to check out a branch that another worktree already has checked out (--force overrides), so give each parallel agent session its own branch. Worktrees isolate files only: ports, databases and other external resources are still shared.Source: git-worktree Documentation
Which Azure Repos branch policies shape the pull request workflow?
/src/settlement/* limits it to PRs touching those files. Check for linked work items and Check for comment resolution block when Required and only warn when Optional. Build validation build expiration: Immediately when the branch is updated (fails status on every update), After <n> hours if the branch has been updated (the compromise for busy branches), or Never. Status checks let external services post required statuses. Path filters must start with / or a wildcard, are separated with ;, use ! to exclude, and apply left to right. CLI: az repos policy approver-count create, az repos policy required-reviewer create.Source: Set and manage branch policies
How do GitHub rulesets and branch protection rules combine for pull request workflows?
Source: About rulesets; Available rules for rulesets
How do you restrict merge types, bypass and branch creation?
tf git permission /deny:CreateBranch for Contributors, then /allow:CreateBranch /branch:feature. Branch policies and locks don't stop branch creation. On GitHub, Require linear history allows only squash or rebase merges.Source: Set and manage branch policies; Require branches to be created in folders
Which branch rules change when Copilot opens or reviews pull requests?
Source: Available rules for rulesets; Configuring code review by GitHub Copilot
Traps in 2.1 questions
- Bypass policies when pushing lets users push directly to main; an emergency PR override needs only Bypass policies when completing pull requests.
- An Optional automatically included reviewer, or Allow requestors to approve their own changes, lets a single author satisfy the policy.
- A 1-approval repository ruleset doesn't override a 2-approval organization ruleset: rules aggregate and the stricter one wins.
- Evaluate mode, or excluding copilot/** from a ruleset, removes enforcement for humans too; a Copilot bypass actor exempts only the agent.
17 questions in the bank test task 2.1. Practice Domain 2
2.2 Configure and manage repositories for Azure DevOps and GitHub
Task 2.2 covers repository administration in Azure Repos and GitHub: permissions and roles, tags, traceability policies, client-side Git hooks, migration from Azure DevOps to GitHub, and repairing or purging history. Questions hinge on least-privilege choices and on exactly what each command or tool does and doesn't move.
- 2.2.1Configure permissions 2 questions
- 2.2.2Configure tags 3 questions
- 2.2.3Implement traceability in repositories, including code quality, code coverage, and deep links to the work item or issue 2 questions
- 2.2.4Create and configure Git hooks that automatically check code New in AZ-4013 questions
- 2.2.5Perform a repository-to-repository migration from Azure DevOps to GitHub New in AZ-4014 questions
- 2.2.6Recover or remove specific data by using Git commands 4 questions
Which repository permissions and roles give least privilege in Azure Repos and GitHub?
Source: Set Git repository permissions; Repository roles for an organization
How do lightweight and annotated tags differ, and who can create or delete them?
git tag v2.4.0 creates a lightweight tag, only a pointer to a commit. git tag -a v2.4.0 -m "Release 2.4.0" creates an annotated tag that stores tagger, date and message. Pushing branches doesn't push tags: run git push origin v2.4.0. git push --all pushes branches only, and --follow-tags pushes only annotated tags. In Azure Repos, the web portal and Visual Studio create annotated tags only; lightweight tags need the command line. Create tag is granted to Contributors by default. Deleting a tag requires Force push at the repository level or on All tags, which inherits from the repository; a tag's creator inherits Force push on that tag. On GitHub, legacy tag protection rules are retired and replaced by tag rulesets: target tags with fnmatch patterns such as v* and use Restrict creations, Restrict updates and Restrict deletions so only bypass actors, for example a release GitHub App, can change them.Source: Use Git tags; Available rules for rulesets
How do you enforce work item links and code coverage on pull requests?
{pipeline-name}/codecoverage status on each PR; the default diff target is 70% of changed lines. Change it in azurepipelines-coverage.yml at the repository root, which applies whatever pipeline builds the code:
coverage:
status:
comments: on
diff:
target: 80%
That status is advisory until a Status checks branch policy requires it. On GitHub, the Restrict code coverage ruleset rule (public preview, needs GitHub Code Quality) blocks merges below a minimum line coverage or above a maximum drop. Deep links: AB#123 in commits or PR descriptions appears in the work item's Development section, which also shows the linked PR's draft, review and checks status.Source: Review and configure code coverage results in Azure Pipelines; Set and manage branch policies
How do you create Git hooks that every developer actually runs?
commit-msg receives one argument, the path of the file holding the proposed message, and a non-zero exit aborts the commit, so it is where you require a work item reference. pre-commit takes no arguments and runs before the message exists; post-commit can't abort; pre-push runs at push time.
#!/bin/sh
grep -qE 'AB#[0-9]+' "$1" || { echo "Add an AB# reference"; exit 1; }
Hooks in .git/hooks aren't versioned or cloned. Commit them to a tracked folder and run git config core.hooksPath .githooks once per clone; later updates arrive with normal pulls. Client hooks stay optional and --no-verify skips them, so mandatory checks belong server-side: branch policies, required status checks, or GitHub push protection, which blocks pushes containing supported secrets and can be enabled organization-wide with GitHub Secret Protection.Source: githooks Documentation; Push protection
How do you migrate repositories from Azure DevOps to GitHub with GitHub Enterprise Importer?
gh ado2gh extension. It migrates Git source with history, pull requests with their user history, attachments and work item links, and repository branch policies (not user-scoped or cross-repo ones). It doesn't migrate work items, Git LFS objects or pipelines, and there are no delta migrations, so halt work during the production run. The GitHub token must be a PAT (classic): repo, workflow and read:org for a migrator, admin:org for organization owners. The Azure DevOps PAT needs Work Items, Code and Identity (Read). gh ado2gh generate-script --ado-org SRC --github-org DEST --output migrate.ps1 --all writes a PowerShell script with one migration per repository; --all adds pipeline rewiring, team creation and Azure Boards integration so teams keep using Pipelines and Boards. To convert pipelines to workflows, use GitHub Actions Importer (audit, dry-run, migrate).Source: Understand migrations from Azure DevOps to GitHub; Migrate your repositories from Azure DevOps to GitHub
How do you undo, recover or purge specific data with Git commands?
git revert <sha> adds a commit that reverses it and keeps history intact; on a branch with policies it goes in through a PR. git reset plus force push, or amending a pushed commit, rewrites shared history and needs Force push. To recover commits lost to a local git reset --hard, find the previous tip in git reflog and run git reset --hard HEAD@{1}; unreferenced commits stay in the local object database. For a leaked secret, revoke or rotate it first; then rewriting history is generally unnecessary. For data that can't be rotated, such as personal data, run git-filter-repo --sensitive-data-removal --invert-paths --path FILE (version 2.47 or later), push every ref with git push --force --mirror origin, then give GitHub Support the number of affected PRs so it can remove cached views and PR refs.Source: Removing sensitive data from a repository; Undo changes
Traps in 2.2 questions
- Write can merge pull requests but can't change merge settings or topics, and Admin can also manage rulesets and delete the repository, so Maintain is the least-privileged fit.
- git push --all and git push --follow-tags don't push a lightweight tag; push the tag by name.
- GEI keeps work item links on pull requests but not the work items; keep Azure Boards connected to the migrated repositories, and use GitHub Actions Importer, not GEI, to convert pipelines.
- git revert or deleting the file in a new commit leaves the data in history; non-rotatable data needs git-filter-repo, a mirror force push and GitHub Support.
18 questions in the bank test task 2.2. Practice Domain 2

Free Domain 2 questions
Contoso is preparing to enable Copilot cloud agent in several GitHub repositories. The security team requires that any change to .github/copilot-instructions.md, to files under .github/agents/, or to .github/workflows/copilot-setup-steps.yml be approved by the Platform Security team before merge, whether a developer or Copilot proposes the change. Developers and Copilot must still be able to propose changes to those files in pull requests. What should you do?
- Create a push ruleset with a Restrict file paths rule that blocks pushes to the three paths in each repository
- Create a branch ruleset that targets copilot/** and add a Restrict updates rule with Platform Security in the bypass list
- Turn off Copilot cloud agent in the repositories until Platform Security has reviewed each of the configuration files
- Assign the paths to Platform Security in CODEOWNERS and enable Require review from Code Owners in the branch ruleset
Show answer and explanation
Answer: D. GitHub's guidance for rolling out Copilot in the cloud is to protect Copilot and MCP configuration files with a CODEOWNERS file and the Require review from Code Owners rule. Changes can still be proposed by anyone, including Copilot, but can't merge without the code owners' approval.
Why the other options are wrong:
- A. A push rule blocks the pushes outright, so developers and Copilot couldn't propose changes to those files at all.
- B. Restricting updates on copilot/** would stop Copilot from pushing its own work and does nothing for human pull requests.
- C. Turning the agent off doesn't create an approval gate and removes the capability the company is rolling out.
Documentation: Building a secure cloud environment for agents in your enterprise; Available rules for rulesets
You are refactoring the ordering service in a local clone of an Azure Repos repository. Your main working tree contains modified and untracked files that are not ready to commit, as shown in the exhibit. A severity 1 bug is reported on the release/4.2 branch and must be fixed immediately. You must not stash, commit, or discard the in-progress work, and you must not download the repository again. Which command should you run first?
$ git status --short
M src/Ordering/OrderService.cs
M src/Ordering/OrderValidator.cs
?? src/Ordering/Pricing/
$ git branch -r
origin/main
origin/release/4.2
- git stash push --include-untracked, then git switch release/4.2
- git clone --branch release/4.2 <repository-url> ../hotfix
- git worktree add -b hotfix/sev1 ../hotfix origin/release/4.2
- git switch -c hotfix/sev1 --track origin/release/4.2
Show answer and explanation
Answer: C. git worktree add creates a linked worktree in a separate folder that shares the existing repository's objects and refs, and -b creates the hotfix branch from origin/release/4.2 and checks it out there. Your refactoring files stay untouched in the main worktree, and nothing is stashed or downloaded again. The Git documentation describes this exact case: a temporary linked worktree for an emergency fix that you remove when done.
Why the other options are wrong:
- A. Stashing the work is explicitly ruled out by the requirements.
- B. A second clone downloads the repository again and keeps a separate object database, which violates the constraint.
- D. Switching branches in the same working tree carries the uncommitted and untracked changes into the hotfix checkout, so the two pieces of work get mixed.
Documentation: git-worktree Documentation
You have an Azure DevOps project that contains an Azure Repos repository named Payments. Pull requests that target main and change files under /src/settlement/ must be approved by at least one member of the Settlement Leads group. Pull requests that change only other files must not require that group. A Settlement Lead who creates a pull request must not be able to satisfy the requirement with their own vote. What should you configure on the main branch?
- Require a minimum number of reviewers set to 1, and add Settlement Leads as an optional automatically included reviewer for /src/settlement/*
- An automatically included reviewers policy for Settlement Leads set to Required, with path filter /src/settlement/*, and Allow requestors to approve their own changes cleared
- An automatically included reviewers policy for Settlement Leads set to Required with no path filter, and Allow requestors to approve their own changes cleared
- An automatically included reviewers policy for Settlement Leads set to Required, with path filter /src/settlement/*, and Allow requestors to approve their own changes selected
Show answer and explanation
Answer: B. A Required automatically included reviewers policy that names a group blocks completion until at least one member of the group approves, and the path filter limits it to pull requests that touch /src/settlement/. Leaving Allow requestors to approve their own changes cleared means the author's own vote doesn't satisfy the policy.
Why the other options are wrong:
- A. An optional reviewer isn't required to approve, so any single approval would satisfy the minimum reviewer policy.
- C. Without a path filter, the group would be required on every pull request to main, which the requirements forbid.
- D. Selecting Allow requestors to approve their own changes lets a Settlement Lead who authored the pull request satisfy the policy alone.
Documentation: Set and manage branch policies
You need a client-side Git hook that rejects a commit when its message doesn't reference an Azure Boards work item. The commit must be refused before it's created, and the hook must read the message that the developer actually wrote. You wrote the following script and made it executable. Where should you save the script?
#!/usr/bin/env bash
msg=$(cat "$1")
if ! echo "$msg" | grep -qE 'AB#[0-9]+'; then
echo "Commit message must reference a work item (AB#1234)"
exit 1
fi
- As .git/hooks/commit-msg
- As .git/hooks/pre-commit
- As .git/hooks/post-commit
- As .git/hooks/pre-push
Show answer and explanation
Answer: A. The commit-msg hook is invoked by git commit with one parameter, the path of the file that holds the proposed message, and a non-zero exit aborts the commit. That matches a script that reads "$1" and exits 1 when no AB# reference is found.
Why the other options are wrong:
- B. pre-commit takes no parameters and runs before the commit message exists, so it can't inspect the message.
- C. post-commit runs after the commit is created and can't abort it.
- D. pre-push runs at push time, after the commit already exists, and receives remote details rather than a message file.
Documentation: githooks Documentation; Introduction to Git hooks
Fabrikam has an Azure DevOps Services organization that uses Azure Repos, Azure Boards, and Azure Pipelines. The company plans to move 120 repositories to GitHub Enterprise Cloud by using GitHub Enterprise Importer. Product owners will keep planning in Azure Boards, and developers must keep linking their GitHub commits and pull requests to existing work items. You need to plan for work item traceability with the least effort. What should you do?
- Run GitHub Enterprise Importer with Azure Boards data included so that the work items become GitHub Issues.
- Use GitHub Actions Importer to convert the work items and their links into GitHub Projects items.
- Keep work items in Azure Boards and connect the migrated repositories through the Azure Boards app.
- Recreate the pull request links manually, because the importer drops work item links on pull requests.
Show answer and explanation
Answer: C. GitHub Enterprise Importer migrates Git source, pull requests, their user history, attachments, work item links on pull requests, and repository branch policies, but not the work items themselves. Azure Boards integrates with GitHub, so keeping work items in Boards and connecting the migrated repositories lets developers continue to use AB# links.
Why the other options are wrong:
- A. The importer doesn't migrate Azure Boards work items to GitHub Issues.
- B. GitHub Actions Importer converts CI/CD pipelines to workflows; it doesn't handle work items.
- D. Work item links on pull requests are part of the data the importer migrates, so manual recreation isn't needed.
Documentation: Understand migrations from Azure DevOps to GitHub; Follow-up tasks
The full bank has 30 more Domain 2 questions and 20-question Domain 2 drills that serve unseen questions first.
Domain 2 drill: $19.99