O'Reilly logo

Pragmatic Version Control Using Git by Travis Swicegood

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 a list of a few of your favorite ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required