Lab 04 - git merge conflicts

Objectives

After completing this exercise, you should be able to

Overview

Git will put conflict markers in your code that look like:

<<<<<<< HEAD 

See also: [dplyr documentation](https://dplyr.tidyverse.org/)   

======= 

See also [ggplot2 documentation](https://ggplot2.tidyverse.org/)  

>>>>>>> some1alpha2numeric3string4

The === separates your changes (top) from their changes (bottom).

On top you see the word HEAD, which indicates that these are your changes.

And at the bottom you see some1alpha2numeric3string4 (it probably looks more like 28e7b2ceb39972085a0860892062810fb812a08f).

This is the hash (a unique identifier) of the commit your collaborator made with the conflicting change.

Your job is to reconcile the changes: edit the file so that it incorporates the best of both versions and delete the <<<, ===, and >>> lines. Then you can stage and commit the result.

Exercise

1. Setup

Each member of your team should open up your project proposal .Rmd file. Assign yourselves numbers (i.e., student 1, student 2, etc.). Everyone should do a pull now for good measure.

2. Avoiding conflicts from the start

Yay no conflicts! That’s because everyone pulled the most up-to-date changes into their local project before making any additional changes. This is why you should always pull first whenever you open a new project session.

3. Easily fixable conflict

You will get an error message that looks like this:

To [your github repo]
! [rejected]        HEAD -> main (fetch first)
error: failed to push some refs to '[your github repo]'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

4. Harder to fix merge conflict

From [your github repo]
5312a1a..f26cd78  main       -> origin/main
Auto-merging Code/analyses.Rmd
CONFLICT (content): Merge conflict in Code/analyses.Rmd
Automatic merge failed; fix conflicts and then commit the result.
<<<<<<< HEAD 

Student 2's work   

======= 

Student 1's work  

>>>>>>> some1alpha2numeric3string4

Conclusion: Follow these instructions carefully and always pull first

Git is very picky about the order in which follow the steps above. If you miss one step (like forgetting to check the stage box) or if you are many steps in front of or behind the remote repository, conflicts become more difficult to merge and they may need to be resolved by command line in the Terminal. We want to avoid this. The morals of the story are:

Here are some additional resources on resolving merge conflicts: