5.4 Handling Conflicts

What happens when you edit the same file in different ways in two different branches and then try to merge them? Git tries to merge them together, but sometimes it can’t.

It is called a conflict when Git can’t automatically merge the commits together. Conflicts occur most commonly when the same area in a file is changed in different ways in each branch. For example, you might use a different variable name in each branch. Git can’t tell which one you want to use, so it stops with a conflict and lets you fix it.

Let’s demonstrate how a conflict works. First, let’s create a new branch called about to add our work in:

 
​prompt> git checkout -b about master
 
​Switched to branch "about"​

Next, add ...

Get Pragmatic Version Control Using Git now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.