CSET-110 Lab:
Merge Conflicts

Today, we're going to learn how to handle merge conflicts. This can be a scary situation to be in when you're new to git. Hopefully our practice will help you feel more comfortable with it. But to practice this, we'll have to intentionally get into trouble first. ;)

You'll have to follow the directions below very carefully, the order of these instructions is very important.


Instructions

  1. Find three partners.
  2. One of you needs to create a new repo on Github called merge-conflicts. Make sure "Initialize with a README" is checked.
  3. Go to the Settings tab, then click Collaborators in the sidebar. Give your partners access to the repo. They'll need to accept the invitation via email.
  4. All four of you should clone the repo locally. Open up the README.md file in your editor and you should see the text # merge-conflicts on line 1.
  5. Now the fun begins:
    1. The owner of the repo needs to use the pencil icon to edit the file directly on Github and replace # merge-conflicts with the words # attempt one. Hit the button to commit this directly on master. Remember, this isn't the usual workflow. We're just trying to replicate having someone else change the remote repo to be different what you have in your local repo. Don't pull this change yet, we're intentionally trying to break things
    2. On your local repository, one of you should use your editor to replace # merge-conflicts with # <your name>
    3. Add the file, commit it, and try to push. You should get a warning saying origin/master has a new change that you don't have. You have successfully created the "problem."
    4. Now we need to fix it. Run git pull which will try to merge the two new changes, but it will fail since we changed the same line in both commits. Now you need to resolve the conflict in your editor
    5. Once you've resolved it, commit it and push.
    6. All four of you should pull and you should all see the first person's name on line 1. Congrats, you've successfully created a merge conflict and resolved it! Now your other partners need to try it. Repeat these inner steps for everyone in your group.