Skip to content

Instantly share code, notes, and snippets.

@ccannon94
Last active January 22, 2022 14:02
Show Gist options
  • Save ccannon94/a75f1f725d33a1834dd7f5feebbc7d4b to your computer and use it in GitHub Desktop.
Save ccannon94/a75f1f725d33a1834dd7f5feebbc7d4b to your computer and use it in GitHub Desktop.
Resolving Merge Conflicts

Resolving Merge Conflicts

Sometimes, especially if you work on your project from multiple computers, you will experience a merge conflict when you attempt to sync with your remote.

GitHub Desktop Merge Conflict

Merge conflicts are a totally normal part of source control management, and resolving them is quite simple.

  • Whether you are resolving the merge conflict on the GitHub desktop app or on the Remote (using the website), the process is quite simple.

  • First, examine the two versions of the file below. Notice that both have different changes on the same line. One was edited in Netbeans, and the other from the GitHub website. Desktop version of conflicted file GitHub version of conflicted file

  • Notice, there in an error in the GitHub Version, java.io.Scanner does not exist. Additionally, we provided an output to the user on the Netbeans version that is missing from the GitHub version.

  • When you open the file to resolve the conflicts in an editor, it will look something like this. Conflicted file in xCode

  • To resolve the conflict, examine an example conflict

<<<<<<< HEAD
import java.util.Scanner;
=======
import java.io.Scanner;
>>>>>>> origin/master
  • The portion above the equals signs is the version currently on the desktop, the version below is currently located on the remote.
  • The first question we should ask is "Why did I use two different imports? Which one is correct?"
  • java.util.Scanner; is the correct import statement, so we should delete the incorrect statement.
<<<<<<< HEAD
import java.util.Scanner;
=======
>>>>>>> origin/master
  • Now, in order to indicate to git that the conflict is resolved by removing the labels.
import java.util.Scanner;
  • Continue until you have resolved all conflicts. The process is demonstrated below Merge conflict resolution gif

  • Finally, save and close the file.

  • Your GitHub Desktop will automatically populate with a commit message Merge conflict commit message GitHub Desktop

  • Commit and Sync, your merge conflict is resolved!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment