Merge conflicts

Git intermedio

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!

Git intermedio

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

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

Opening the file

nano README.md

README file showing conflict sections using nano

Git intermedio

Git conflict syntax

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

Git intermedio

Resolving the conflict

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

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

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!
Git intermedio

Let's practice!

Git intermedio

Preparing Video For Download...