Skip to content

Exercise Resolving Merge Conflicts

Robert Adams edited this page Sep 8, 2018 · 3 revisions

Prerequisites

Exercise

To simulate a merge conflict as if you were working with a partner, we have already created a branch called origin/merge-exercise in your repository when you cloned it. Run these commands:

git checkout master
git merge origin/merge-exercise

You should see the following output:

merge-conflict

Run git status to see what files need to be merged:

merge-status

Open up the conflicting file dog.c in a text editor. You should see a bunch of weird markers like >>>, ===, and <<<.

merge-markers

Everything between the <<<<< HEAD and ===== are YOUR local changes. Everything between the ==== and >>>> origin/merge-exercise are the REMOTE's changes (e.g. your partner's).

To fix a merge conflict, simply edit the file until it looks the way you want it to. This means removing all the >>>, ===, and <<< markers, and then save the file. This is how I resolved my conflict, but you may resolve yours differently.

merge-resolved

Once you've edited and saved the file:

git add dog.c
git commit -m "merged my dogs"

TADA! You're done! Take a look at your git history now: git lg

merge-history

You'll noticed that the two separate branches have now merged together with your merged my dogs commit. Now push your commits to github and you're done with the exercise!

git push origin master

Finish Bootcamp

Go back to the main page.

You can’t perform that action at this time.