GitHub Desktop Tutorials

Merge Conflicts

What is a Merge Conflict

It is when your local copy of your project is older then the GitHub version. How does this happen, you ask? If one person commits a change on the same file you are working on, that change doesn't automatically sync with your local copy. If you attempt to commit changes on the same file, a merge conflict happens because GItHub doesn't know which version is correct. Clicking "Sync" before commiting can fix miner merge conflicts, but sometimes it can't be avoided.


Example of a Merge Conflict

  1. Sync a local copy from the GitHub Desktop
  2. Sync button is on the top right-hand side
  3. Open a file from your project using a text editor or IDE of choice.
  4. Showing a copy of index.html in text editor

    Note: This is a local copy that you are working on.

  5. Let's say that a team member decides to work on the same file and commits a few changes to the existing code.
  6. Example of the code being changed by another team member.
  7. In the meantime, you just finished writing an update to your local copy.
  8. Example of local copy without current updates.
  9. Type a summary of your update.
  10. Click "Commit to master".
  11. Example of summary
  12. Click "Sync" on the top right-hand side.
  13. Sync button is on the top right-hand side
  14. An error message will indicate a merge conflict.
  15. Error message pops up in the center of application.
  16. Click "Close"

How to fix

  1. In the center of the application, you will see two options. I recommend clicking "Show in Folder", so you can open the file in conflict from a text editor. You can use the other option if it is a webpage to see the conflict.
  2. In the pop-up screen, Show in Finder is the left button and Open with Explorer is on the right
  3. For now click, "Show in Finder".
  4. Right-click the file showing merge conflict.
  5. Open with your favorite text editor.
  6. Opened file with Sublime text-editor
  7. You should see something simliar to this.
  8. File displays two versions of the same code with less than signs, equal signs, and greater than signs.

    Notes: You probably notice some weird looking markers. These markers represent the merge conflict.

    • <<<<<< HEAD: Represents the begining of a merge conflict.
    • ======: Represents where two merged files are different.
    • >>>>>>> origin/master: Represents where the merge conflict ends.
    In our example between the <<<<<< HEAD and ====== this is our version of the code and between ==== and >>>>> is the new version.

  9. Check through the GitHub commit history to see who commited last, then talk with the team members involved in the merge conflict.
  10. History based on GitHub application

    Note: Not all merge conflicts look the same, so the key is communicating with your team and reviewing the code in conflict.

  11. After discussion, correct the conflict by deleting the no longer used code and remove the headers.
  12. Code corrected with markers removed.
  13. Type a summary of update.
  14. Click "Commit to master".
  15. Updated summary fixed merge conflict
  16. Click "Sync" on the top right-hand side.
  17. Sync button is on the top right-hand side
  18. Now the merge conflict is resolved.
  19. History showing resolved commit.