Merge conflicts

Intermediate Git

George Boorman

Curriculum Manager, DataCamp

Conflicts

  • Conflict

    • Inability to resolve differences in the contents of one or more files between branches
  • Edit the same file in two branches

  • Try to merge

  • Git doesn't know what version to keep

  • Conflict!

Intermediate Git

Conflicting versions of README.md

documentation branch

# Contents and usage

This repo contains source code 
for the DataCamp website.

It also contains source code for an 
AI-Assistant (recommendation system) 
that takes prompts from learners and 
returns suggested content
that they might be interested in. 

It is for internal use only, 
external access is prohibited.

main branch

# Contents and usage

This repo contains source code 
for the DataCamp website.

It is for internal use only, 
external access is prohibited.
Intermediate Git

Merging

  • From the main branch
git merge documentation
Auto-merging README.md
CONFLICT (add/add): Merge conflict in README.md
Automatic merge failed; fix conflicts and then commit the result.
Intermediate Git

Opening the file

nano README.md

README file showing conflict sections using nano

Intermediate Git

Git conflict syntax

annotated conflict file showing contents in main branch versus the documentation branch

Intermediate Git

Resolving the conflict

nano web editor deleting the Git syntax <<<<<<< documentation, =======, and >>>>>>> HEAD

  • Save: Ctrl + O (not Ctrl + 0), then Enter
  • Exit: Ctrl + X
Intermediate Git

Merging the branches

  • Merging now that the conflict is resolved
git add README.md
git commit -m "Resolving README.md conflict"
git merge documentation
Already up to date.
  • Prevention is better than cure!
Intermediate Git

Let's practice!

Intermediate Git

Preparing Video For Download...