Search⌘ K

Handling Merge Conflicts

Explore how to manage merge conflicts in Git by learning what causes conflicts during merges and how to resolve them carefully. This lesson guides you through identifying conflict markers in files, deciding how to reconcile differing changes, and completing merges successfully by committing resolved code.

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 ...