Skip to main content
Dan Rodney/2 min read

How to Handle Merge Conflicts

Resolve a Merge Conflict

1

Identify Conflicts

git status shows files with conflicts after a failed merge.

2

Open the Files

Look for <<<<<< / ====== / >>>>>> markers — your changes vs theirs.

3

Edit & Stage

Pick the right code, remove markers, git add the file.

4

Complete the Merge

git commit finalizes the merge with the resolved content.

Build Programming Foundations at Noble Desktop

Noble Desktop's Full-Stack Web Development Certificate teaches Git alongside the modern web stack — a must for any developer.

Learn how to resolve merge conflicts in Git by viewing both sets of changes and deciding which to keep, with our step-by-step guide on handling them.

Merging Changes

Sometimes you’ll get a conflict when pulling, reverting commits, merging branches, etc. For example, you and another developer unknowingly both work on the same part of a file. The other developer pushes their changes to the remote repo. When you then pull them to your local repo you’ll get a merge conflict. Luckily Git has a way to handle conflicts, so you can see both sets of changes and decide which you want to keep.

What to Do with a Merge Conflict

  1. When you get a merge conflict, open a conflicted file. They are listed in the Source Control panel under Merge Changes.
  2. In the conflicted file, look for these conflict markers:

    <<<<<<< HEAD (Current Change) Marks the start of the changes.

    ======= Divides your changes from the changes in the other branch.

    >>>>>>> branch-name (Incoming Change) Marks the end of the changes.

  3. Now you must decide how to resolve the conflict. Above the change you can choose various ways to handle it:

    • Accept Current Change
    • Accept Incoming Change
    • Accept Both Changes
    • Compare Changes

    Look at the code and choose whichever is appropriate for this case. After accepting the change, you can make further edits to the code as needed.

  4. Save the file.
  5. After you’ve handled all the conflicts, in the Source Control panel stage the changes by hovering over Merge Changes and clicking the plus (+) that appears to its right.
  6. At the top of the Source Control panel click the Commit button .
  7. Push whenever you’re ready to upload those changes to GitHub so others can get them.