Git Merge Conflicts

When you’re doing a Git Merge, sometimes you have made changes to the same line of code that someone else also changed. When you try to merge your files you will get an error message that will look something like this:

When this happens, Git will create a special version of the files that had the conflicts that marks where the conflicts are. You have to go in and edit those files and resolve the conflicts, then commit your changes like any other change.

Here is a quick rundown of the process:

  1. Click on a file with merge conflicts (should be in separate Merge Conflicts area in Source Control)
  2. Edit the file to make it look like how it should be. Git will show the conflict by using the following dividers:
    1. <<<<<<<<< HEAD (this is what the original file has)
    2. ========= (this ends the original file and starts your changes)
    3. >>>>>>>>> name-of-branch (this ends your changes)
  3. Remember to remove the three dividers above. If you’re using GitLens you can click one of the three Accept links and it will automatically remove the dividers.
  4. Commit your changes
  5. Push your changes up to GitHub (you can do a git push or click the Sync Changes button in VS code).

And here it is in more detail with some images.

[1] Click on a file with merge conflicts (

They should be in the separate Merge Changes area in Source Control.

screenshot of files in Merge Changes area
click file under Merge Changes area to see the conflict

[2] Edit the file to make it look like how it should be.

Git will add three dividers to the file in each area where there are conflicts (there can be multiple of these per file depending on the number of conflicting lines in the file).

<<<<<<<<< HEAD (start original file code)
========= (end original and start your changes)
>>>>>>>>> name-of-branch (end your changes)

Here is an example:

screenshot of file with merge conflict shown

You have two options to edit the file:

  1. If you have GitLens installed then you will be able to click one of thea Accept links:
    1. Accept Current Change: uses the existing code and removes yours.
    2. Accept Incoming Change: uses your code and removes existing code
    3. Accept Both Changes: keeps both sets of code
  2. Manually edit the file. You just go in and change the file to make it keep the lines of code you want.

[3] Remember to remove the three dividers.

This is if you did it manually. If you used the Accept links then it will happen automatically. Your file should look something like this with no dividers:

File with conflicts removed.

[4] Commit your changes

Do this like any other commit:

  1. Stage files (click the + by the files you changed)
  2. Write commit message
  3. Click to commit.

[5] Push your changes up to GitHub.

You can do a git push or click the Sync Changes button in VS code. It’s important to do this so your changes are saved there and if you’re in a group other people will be able to see your changes.

Leave a comment