Introduction to Git and GitHub

Session - Conflicts!

Zoë Turner

Conflicts!

Conflicts can happen when you merge a branch and can occur when working with others, or even yourself!

Let’s create a conflict…

Your Turn

  1. usethis::pr_init("author_change")
  2. Replace the author in the Quarto YAML with author: Person A and Render
  3. gert::git_commit_all("Added Person A as author")
  4. usethis::pr_push()
  5. In GitHub create a pull request to main using Merge pull request and do the merge

Not pulling from main

We’ll miss the pr_finish() part because this function reduces the possibility of conflict as it pulls changes made on main

Together we will…

… create another branch in RStudio, not {usethis}, as we miss the steps that reduce conflicts:

  1. Go to the main branch using the RStudio Git pane
  2. Create a branch in that pane using the button next to person-b
  3. Replace the author in the Quarto YAML with author: Person B and Render
  4. Tick the box next to the file and commit using the Git pane in RStudio
  5. Push the changes using RStudio Git pane (the button is not greyed out)
  6. In GitHub create a pull request to main using Merge pull request and do the merge

Conflict in GitHub!

Screenshot of GitHub merge conflict with the Resolve Conflict grey section of the Pull Request

Looking for the symbols

To resolve the conflict we need to edit (in this case delete) one of the names and also delete all the merge text:

<<<<<< person-b
=======
>>>>>> main

This can be done in GitHub and ends with a new commit.

Seeing the conflict locally

To see the same conflicted files locally:

  1. On the branch with the conflict (person-b)
  2. Go to the Console ($) and type usethis::pr_merge_main()
✔ Pushing local 'author_change' branch to 'origin/author_change'.
• Create PR at link given below
✔ Opening URL 'https://github.com/Letxuga007/project/compare/author_change'
> usethis::pr_merge_main()
✔ Pulling changes from 'origin/main'.
Merge has resulted in merge conflict(s).
There are 1 conflicted files:
* 'my_report.qmd'
Are you ready to sort this out?
If so, we will open the conflicted files for you to edit.

1: Yes, I'm ready to resolve the merge conflicts.
2: No, I want to abort this merge.

Selection: 

End session