Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
Exercise Resolving Merge Conflicts
- Make sure you've done the Github forking exercise
- Make sure you've done the Committing and pushing 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:
git status to see what files need to be merged:
Open up the conflicting file
dog.c in a text editor. You should see a bunch of weird markers like
Everything between the
<<<<< HEAD and
===== are YOUR local changes. Everything between the
>>>> 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
<<< markers, and then save the file. This is how I resolved my conflict, but you may resolve yours differently.
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:
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
Go back to the main page.