# Resolving Merge Conflicts Using the Command Line and Azure DevOps

When working in a version-controlled environment like Git, it's common to encounter merge conflicts—especially when multiple contributors are working on the same codebase. This blog will walk you through how to resolve merge conflicts using the command line and Azure DevOps.

---

## **What is a Merge Conflict?**

A merge conflict occurs when two or more branches have changes in the same section of a file, and Git doesn't know which change to keep. This happens when merging branches or rebasing, and requires manual intervention to resolve.

---

### **1\. Resolving Merge Conflicts Using the Command Line**

#### **Step-by-Step Guide**

1. **Attempt the Merge:**
    
    First, you try to merge the branch you want to integrate into your current branch (e.g., merging `dev` into `main`):
    
    ```plaintext
    git checkout main
    git merge dev
    ```
    
    If there are conflicts, Git will pause the merge and notify you about the conflict:
    
    ```plaintext
    Auto-merging turbo.json
    CONFLICT (content): Merge conflict in turbo.json
    Automatic merge failed; fix conflicts and then commit the result.
    ```
    
2. **Check Which Files Have Conflicts:**
    
    To list all files with conflicts, you can use:
    
    ```plaintext
    git status
    ```
    
    or
    
    ```plaintext
    git diff --name-only --diff-filter=U
    ```
    
    This will show files that are in the "unmerged" state.
    
3. **Open the Conflicted Files:**
    
    Open the conflicted files in your preferred editor (e.g., `turbo.json`). You’ll see markers that Git uses to indicate the conflicting sections:
    
    ```plaintext
    <<<<<<< HEAD
    Your changes in the current branch.
    =======
    Changes from the branch you're trying to merge.
    >>>>>>> dev
    ```
    
    Here:
    
    * `HEAD` contains the code from your current branch (e.g., `main`).
        
    * The part after `=======` shows the incoming changes from the branch you’re merging (e.g., `dev`).
        
4. **Resolve the Conflict:**
    
    You need to manually edit the file, decide which changes to keep, and remove the conflict markers (`<<<<<<<`, `=======`, `>>>>>>>`).
    
    Example of resolved content:
    
    ```plaintext
    jsonCopy code{
        "version": "1.0",
        "build": "npm run build-dev"
    }
    ```
    
5. **Stage the Resolved Files:**
    
    Once the conflicts are resolved, mark the files as resolved by adding them to the staging area:
    
    ```plaintext
    git add turbo.json
    ```
    
6. **Complete the Merge:**
    
    After staging all resolved files, finalize the merge by committing:
    
    ```plaintext
    git commit
    ```
    
    This will create a merge commit and successfully combine the two branches.
    
7. **Push the Changes:**
    
    Finally, push your changes to the remote repository:
    
    ```plaintext
    bashCopy codegit push origin main
    ```
    
    # **Resolving Merge Conflicts in Azure DevOps**
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1728567475189/7008ef3e-f5a7-49ed-b448-a93265e62d60.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1728567485177/13421c21-7a82-41cc-b90a-4e39e39e430a.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1728567493261/bacc06f8-f48a-417b-8817-d0ff443c785a.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1728567503119/d2893980-3ce1-483f-93cc-2f9d374e1826.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1728567515867/8b1c6d4f-4e9e-4f88-a28d-64d5d2e9a505.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1728567523319/588a2f99-8a4c-4c60-90ed-d0f0a5eee140.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1728567533814/9f2c9a4d-799a-4b75-8ecc-3c5fb24f42b3.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1728567552113/01d02faf-c8fa-416c-84f9-154b881d3d30.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1728567561727/9e2885ec-cdf6-4a99-9fc0-d6de68345604.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1728567577257/9a985012-3230-4247-bd1a-d8147dda7424.png align="center")
