Console9

How to resolve a merge conflict in Git

Identify and resolve merge conflicts in Git by editing conflicted files and completing the merge.

How to resolve a merge conflict in Git

Identify and resolve merge conflicts in Git by editing conflicted files and completing the merge.

Prerequisites

  • Git installed.
  • A repository with two branches that modify the same lines in a file.

Step-by-Step: Resolve a Merge Conflict in Git

  1. Start the merge. Git reports which files have conflicts:

    git merge feature-branch
    Auto-merging config.yaml
    CONFLICT (content): Merge conflict in config.yaml
    Automatic merge failed; fix conflicts and then commit the result.
  2. Open the conflicted file. Git marks the conflicting sections with <<<<<<<, =======, and >>>>>>>:

    <<<<<<< HEAD
    max_connections: 100
    =======
    max_connections: 200
    >>>>>>> feature-branch
  3. Edit the file to resolve the conflict. Remove the conflict markers and keep the correct content:

    max_connections: 200
  4. Stage the resolved file and commit:

    git add config.yaml
    git commit -m "Resolve merge conflict in config.yaml"

How to Verify the Merge Is Complete

git status should show a clean working tree with no unmerged files.