How to resolve merge conflicts in Azure DevOps?

171    Asked by DavidEDWARDS in Devops , Asked on Jul 3, 2024

I am currently engaged in a particular task that is related to Azure DevOps. During the time of workflow, I encountered a particular conflict which is between my branch and the main development branch. What should be the steps to resolve and troubleshoot this particular issue? 

Answered by David Piper

 In the context of DevOps, here are the steps given:-


You can start by pulling the latest changes first from the main branch into your local branch. This would help you in revealing any conflicting changes.

Git checkout main
Git pull origin main
Git checkout your_branch
Git merge main

Resolving conflicts

Now you should try to open the conflicted files in your code editor. Look for the marked with <<<<<<<, ========= and >>>>>>>>> which would indicate that there is a conflict between the branches. You can manually edit the files to reconcile the differences and remove the conflict markers.

Review the changes

After completing the process of resolving the conflict, now you can review the changes so that you can ensure that they make sense and also maintain functionality.

Commit the changes

You can stage the resolved files and then commit the changes.

Git add 
Git commit -m “Resolved merge conflict”

Pushing the changes

Now you can push the resolved change to Azure DevOps.

  “git push origin your _ branch”

Here is a combined example given which would include all the steps to resolve merge conflicts in both Java and Python files by using the git command in one sequence:-

# Switch to the main branch and pull the latest changes

Git checkout main
Git pull origin main
# Switch back to your branch and merge main into it
Git checkout your_branch
Git merge main
# Resolve conflict in Main.java
# Open Main.java in your code editor, resolve conflicts, and save changes
# Example:
# public class Main {
# public static void main(String[] args) {
# <<<<<<< HEAD
# System.out.println(“Hello from branch A”);
# =======
# System.out.println(“Hello from branch B”);
# >>>>>>> main
# }
# }
# Resolve by keeping both lines:
# public class Main {
# public static void main(String[] args) {
# System.out.println(“Hello from branch A”);
# System.out.println(“Hello from branch B”);
# }
# }
# Stage and commit Main.java
Git add Main.java
Git commit -m “Resolved merge conflict in Main.java”
# Resolve conflict in script.py
# Open script.py in your code editor, resolve conflicts, and save changes
# Example:
# def main():
# <<<<<<< HEAD
# print(“Hello from branch A”)
# =======
# print(“Hello from branch B”)
# >>>>>>> main
# Resolve by keeping both print statements:
# def main():
# print(“Hello from branch A”)
# print(“Hello from branch B”)
# Stage and commit script.py
Git add script.py
Git commit -m “Resolved merge conflict in script.py”
# Push changes to your branch
Git push origin your_branch
# Verify and complete merge in Azure DevOps or CI/CD pipeline
# Ensure the build passes and complete the merge in your pull request if applicable


Your Answer

Interviews

Parent Categories