Handling Merge Conflicts

Explore how you can handle merge conflicts.

Don’t panic

This is where a lot of people panic when merging, and it helps to understand what’s going on by running through it by hand and with a toy example. So, what exactly happens when you perform a merge?

Merge conflict

When you run a merge, Git looks at the branch you are on (here it is master) and the branch you are merging in (experimental) and works out the first common ancestor. In this case, it’s point C, as that’s where you branched experimental.

It then takes the changes on the branch that you are merging in from that first common ancestor and applies them to the branch you are on in one go. These changes create a new commit, and the git log graph shows the branches joined back up.

Sometimes the changes made on the branches conflict with one another. That means the changes altered the same lines. In this case, the D, F, and G of the master changed the same lines as the E and H of experimental.

Get hands-on with 1200+ tech skills courses.