Azure Repos – Branch Management, Merging, and Merge Conflict Resolution
1. What are Branches in Azure Repos?
A branch is an independent line of development in a Git repository. It allows developers to work on features, bug fixes, and releases without directly modifying production code.
Azure Repos uses Git for branching and merging and provides additional features such as Pull Requests, code reviews, branch policies, and build validation.
Simple example
Suppose you are developing an ASP.NET Core Web API application with three developers.
-
Developer A works on the Customer API.
-
Developer B works on the Account API.
-
Developer C fixes a production issue.
Instead of everyone modifying main, each developer creates a separate branch.
Common branch types
|
Branch |
Purpose |
|---|---|
|
|
Production-ready code |
|
|
Ongoing development and integration |
|
|
New feature development |
|
|
Fix defects found during development |
|
|
Prepare code for production release |
|
|
Fix urgent production defects |
Azure Repos does not require this branching strategy. Teams can also use GitHub Flow or trunk-based development.
2. How do you manage branches in Azure Repos?
Branches can be managed through Git commands, Visual Studio 2026, or the Azure DevOps web portal.
Step 1: Create a feature branch
First, update your local develop branch.
git switch develop
git pull origin develop
Create a new branch:
git switch -c feature/customer-api
Step 2: Develop and commit changes
git add .
git commit -m "Implemented Customer API"
Step 3: Push the branch to Azure Repos
git push -u origin feature/customer-api
The feature branch is now available in Azure Repos.
Important branch commands
|
Command |
Purpose |
|---|---|
|
|
List local branches |
|
|
List local and remote-tracking branches |
|
|
Switch to another branch |
|
|
Create and switch to a new branch |
|
|
Push branch to Azure Repos |
|
|
Delete a merged local branch |
|
|
Delete a remote branch |
3. What is Git Merge?
Git merge is the process of integrating changes from one branch into another.
Example
You have two branches:
-
develop– Contains the existing application. -
feature/customer-api– Contains the newly developed Customer API.
After completing development, you want to integrate the Customer API into develop.
Before Merge
develop
A ─── B
\
feature C ─── D
After Merge
develop
A ─── B ─────── M
\ /
feature C ─── D
M = Merge Commit
How to merge locally
Switch to the target branch:
git switch develop
Update it:
git pull origin develop
Merge the feature branch:
git merge feature/customer-api
Push the merged changes:
git push origin develop
Important: For protected branches in Azure Repos, use a Pull Request instead of directly pushing merged changes.
4. Types of Git Merge
Git commonly performs two types of merges.
A. Fast-Forward Merge
A fast-forward merge occurs when the target branch has no new commits since the feature branch was created.
Before:
main A ─── B
\
feature C ─── D
After:
main A ─── B ─── C ─── D
Git simply moves the target branch pointer forward.
Advantages: Simple history and no additional merge commit.
B. Three-Way Merge
A three-way merge occurs when both branches have progressed independently.
Before:
main A ─── B ─── E
\
feature C ─── D
After:
main A ─── B ─── E ─── M
\ /
feature C ─── D
Git uses the common ancestor and the latest commits from both branches to combine changes.
Key point: A three-way merge may succeed automatically or produce merge conflicts.
5. How do you merge branches in Azure Repos?
In team environments, merging is usually performed through Pull Requests.
Typical workflow
Developer
↓
Creates feature/customer-api
↓
Develops and Commits
↓
Pushes to Azure Repos
↓
Creates Pull Request
↓
Code Review
↓
Build Validation
↓
Reviewers Approve
↓
Merge into develop
Steps in Azure DevOps
-
Open Azure DevOps → Repos → Pull requests.
-
Click New pull request.
-
Select source branch:
feature/customer-api. -
Select target branch:
develop. -
Enter the title and description.
-
Assign reviewers.
-
Create the Pull Request.
-
Resolve comments and satisfy required policies.
-
Click Complete to merge.
Azure Repos supports different merge strategies:
|
Strategy |
Explanation |
|---|---|
|
Merge commit |
Preserves branch history and creates a merge commit |
|
Squash merge |
Combines feature changes into one commit |
|
Rebase and fast-forward |
Replays commits on the target and moves the target pointer |
|
Rebase with merge commit |
Rebases commits and then creates a merge commit |
6. What is a Merge Conflict?
A merge conflict occurs when Git cannot automatically combine changes from two branches.
This commonly happens when two developers modify the same lines of code differently.
Example
Suppose both developers modify the CalculateInterest() method.
Developer A changes the code in develop:
public decimal CalculateInterest(decimal amount)
{
return amount * 0.05m;
}
Developer B changes the same code in feature/interest-api:
public decimal CalculateInterest(decimal amount)
{
return amount * 0.06m;
}
When the feature branch is merged into develop, Git may not know which calculation should be retained.
Git reports a merge conflict.
How does the conflict appear?
<<<<<<< HEAD
return amount * 0.05m;
=======
return amount * 0.06m;
>>>>>>> feature/interest-api
Explanation:
-
<<<<<<< HEAD– Current branch changes. -
=======– Separates conflicting changes. -
>>>>>>> feature/interest-api– Incoming branch changes.
The developer must decide which implementation is correct.
7. How do you resolve Merge Conflicts?
Suppose your feature branch has a conflict with develop.
Step 1: Switch to your feature branch
git switch feature/interest-api
Step 2: Fetch the latest remote changes
git fetch origin
Step 3: Merge the latest develop changes
git merge origin/develop
If a conflict occurs, Git reports something similar to:
Auto-merging InterestService.cs
CONFLICT (content): Merge conflict in InterestService.cs
Automatic merge failed; fix conflicts and then commit the result.
Step 4: Identify conflicting files
git status
Example:
Unmerged paths:
both modified: InterestService.cs
Step 5: Resolve the conflict
Open the conflicting file in Visual Studio 2026.
Review both implementations and determine the correct business logic.
For example, if the approved interest rate is 6%:
public decimal CalculateInterest(decimal amount)
{
return amount * 0.06m;
}
Remove the conflict markers.
Step 6: Stage the resolved file
git add InterestService.cs
Step 7: Complete the merge
git commit -m "Resolved interest calculation conflict"
Step 8: Push the changes
git push origin feature/interest-api
The existing Azure Repos Pull Request is automatically updated.
Important: Run the application and relevant tests after resolving conflicts. A syntactically correct merge may still contain incorrect business logic.
8. How to resolve Merge Conflicts in Visual Studio 2026
Visual Studio provides a graphical interface for resolving Git conflicts.
Steps
-
Open the solution in Visual Studio 2026.
-
Navigate to Git → Git Changes.
-
Fetch and merge the latest target branch changes.
-
If conflicts occur, open the Unmerged Changes section.
-
Select the conflicting file.
-
Open the merge editor.
-
Compare the current and incoming changes.
-
Accept the appropriate changes or manually combine them.
-
Save the resolved file.
-
Stage the changes and complete the merge commit.
-
Push the updated feature branch.
The merge editor lets you compare the conflicting versions and review the resulting code before committing.
9. Merge vs Rebase
Both merge and rebase are used to integrate changes from another branch, but they work differently.
|
Git Merge |
Git Rebase |
|---|---|
|
Combines branch histories |
Replays commits onto a new base |
|
Usually preserves existing commit identities |
Rewrites the rebased commits |
|
May create a merge commit |
Typically creates a linear history |
|
Suitable for shared branches |
Commonly used on private feature branches |
|
Does not rewrite existing commits |
Can require force pushing after rebasing a published branch |
Merge example
git switch feature/customer-api
git merge origin/develop
Rebase example
git switch feature/customer-api
git rebase origin/develop
Best practice: Avoid rebasing shared branches because rewriting published commit history can disrupt other developers.
10. Common Merge Conflict Scenarios
|
Scenario |
Recommended action |
|---|---|
|
Two developers modify the same lines |
Review both changes and manually resolve |
|
Feature branch is behind |
Fetch and merge or rebase latest changes |
|
Conflict occurs during PR |
Resolve on the feature branch and push |
|
Incorrect merge resolution |
Correct the code and commit the fix |
|
Want to cancel an ongoing merge |
|
|
Want to cancel an ongoing rebase |
|
|
Multiple conflicting files |
Resolve each file, stage, test, and commit |
How to minimize merge conflicts
-
Create short-lived feature branches.
-
Frequently fetch and integrate changes from
develop. -
Keep Pull Requests small and focused.
-
Avoid unnecessary changes to shared files.
-
Communicate when multiple developers modify the same functionality.
-
Complete feature branches promptly.
11. Advantages and Disadvantages
Advantages of Branching and Merging
-
Multiple developers can work independently.
-
Production code remains isolated from ongoing development.
-
Features can be reviewed before integration.
-
Supports parallel development and release management.
-
Git maintains a history of changes.
Disadvantages
-
Merge conflicts may occur.
-
Long-lived branches can become difficult to integrate.
-
Incorrect conflict resolution may introduce defects.
-
Complex branching strategies require team coordination.
12. Important Interview Questions and Answers
Q1. How do you manage branches in Azure Repos?
We use a branching strategy with main, develop, feature, and hotfix branches. Developers create feature branches, commit and push changes, and use Pull Requests to merge into protected branches.
Q2. What is the difference between merge and rebase?
Merge combines branch histories while preserving existing commits. Rebase replays commits on another base, creating a linear history but rewriting the rebased commits.
Q3. What causes merge conflicts?
Merge conflicts occur when Git cannot automatically combine changes, commonly because developers modify the same lines differently or one developer deletes code modified by another.
Q4. How do you resolve a merge conflict?
Fetch the latest changes, merge the target branch into the feature branch, review conflicting files, resolve the code, stage the changes, commit, test, and push.
Q5. Can merge conflicts be resolved in Azure DevOps?
Yes. Azure Repos identifies merge conflicts in Pull Requests. Developers commonly resolve them locally using Visual Studio or Git and push the updated branch.
Q6. What happens if you merge the wrong branch?
If the merge has not been pushed, it may be possible to undo it locally. If it has already been merged into a shared branch, use an appropriate revert strategy rather than rewriting shared history.
Q7. How do you prevent merge conflicts?
Keep feature branches short-lived, regularly integrate changes from the target branch, avoid overlapping modifications, and maintain clear team communication.
Q8. What is a squash merge?
A squash merge combines changes from a feature branch into a single new commit on the target branch, helping maintain a concise commit history.
13. Real-Time Interview Scenario
Question: Two developers are working on the same ASP.NET Core application. Both modify the same service method. How do you handle the merge conflict in Azure Repos?
Sample answer:
In our project, developers work on separate feature branches in Azure Repos.
When a developer creates a Pull Request, Azure Repos checks whether the feature branch can be merged into the target branch.
If a merge conflict occurs, the developer fetches the latest changes from the target branch and merges them into the feature branch.
We use Visual Studio's Git merge editor to review the conflicting changes. We discuss the correct implementation with the other developer if required and resolve the conflict based on business requirements.
After resolving the conflicts, we run the application and relevant unit tests to ensure everything works correctly.
Finally, we commit and push the resolved changes. The existing Pull Request is updated, and the code-review and build-validation process continues.
Once all required checks pass, we complete the Pull Request and merge the changes into the target branch.
14. Key Points to Remember
-
Branch: Independent line of development.
-
Merge: Integrates changes from different branches.
-
Fast-forward merge: Moves the branch pointer forward without creating a merge commit.
-
Three-way merge: Combines diverged branch histories using a common ancestor.
-
Merge conflict: Git cannot automatically reconcile changes.
-
Pull Request: Controlled review and merge process.
-
Rebase: Replays commits on another base.
-
Squash merge: Combines changes into one commit.
-
Conflict resolution: Review, correct, test, commit, and push.
-
Branch policies: Protect important branches from unreviewed changes.
One-line interview answer: In Azure Repos, we manage development using feature and protected branches, integrate changes through Pull Requests, and resolve merge conflicts by fetching the latest target branch, reviewing conflicting code, manually resolving differences, testing, and pushing the corrected changes before completing the merge.