Git & GitHub: Merge Conflicts

Git & GitHub: Merge Conflicts

When I first learned Git, one of the most
confusing topics to me was merge conflicts. It seems like I always found
myself in a merge conflict I didn’t know why and I didn’t know how to get out of
it. But really they’re not that complicated. A merge conflict occurs when
there’s been a change in the same file in the same line on the two branches
you’re trying to merge together. So here, for example, if we’re working in index.html on two branches and there have been changes in line four in both files that will
generate a merge conflict. Now, for example ,this is just one conflict there
could be multiple files or even multiple portions of the same file with conflicts
but for now let’s keep it simple. So, Git tells you there’s a conflict. What do you do next? My favorite next
step is to run ‘git status’. It’s an easy way to clear my head and
see exactly which files have the conflicts in them. Once I know what file
to look at, I open it up in my favorite text editor and I look for these merge
conflict markers. Once you find the merge conflict markers, all you need to do is
pick the version of code that you’d like to keep and get rid of the merge
conflict markers. One version will be above equal signs and the other will be
below. You can pick one, delete them both, or create something totally new. Git doesn’t care. Just make sure the code
looks the way you want it to and get rid of the merge conflict markers. Save those
changes and commit them and Git will know the merge conflict has resolved.

2 thoughts on “Git & GitHub: Merge Conflicts

  1. This is great, Briana, thanks! One question – at the end you say once you've fixed the merge conflict you should commit your changes again. Does that resolve the merge process you were in, or do you need to merge again?

Leave a Reply

Your email address will not be published. Required fields are marked *