Collaborate With GitHub

Session 5

September 19, 2023

Review

Word Bank

repo | commit | remote | push | pull | add

  1. A collection of files tracked by git
  2. A snapshot of the state of a repository
  3. git ___ is used to tell git to track a file
  4. For example, a repo on GitHub
  5. git ____ is used to synchronize changes on your computer with a remote

Review

Did anyone add a repo to GitHub? What difficulties did you encounter?

Collaborating with GitHub

Example repo

Dealing with Conflicts

  • What happens when two people make conflicting edits to a file and push them?

  • Creates a merge conflict

Ok, try git pull

Merge, rebase, fast-forward??

  • These are alternative ways to deal with conflicts—we won’t get into the details

  • For now, we recommend you stick with the “merge” option

Use:

git config pull.rebase false

Or, if you want to set this option for all future repos too

git config --global pull.rebase false

Fixing a Merge Conflict

  • Resolve the conflict however you want (i.e. keep one of the two sections)

  • Delete all lines with <<<<<<<, >>>>>>>, or =======

  • Save and commit

Avoid merge conflicts by working on branches

Each person works on a “branch”—an independent series of commits that can be merged back into the “main” branch.

gitGraph
   commit
   commit
   branch person_1
   commit
   commit
   commit
   checkout main
   branch person_2
   commit
   commit
   checkout main
   merge person_1
   merge person_2
   commit
       

Working on a Branch

  • Make a new branch using RStudio’s Git pane (for this demo, use your name)

  • Commit changes and push to your branch

  • View changes on GitHub

Pull Requests

A request to merge changes into the main branch

  • Need another volunteer to share screen and be guided through making a pull request

  • This time, everyone can follow along!

Forks

What if you don’t have permission to push to a GitHub repo but you want to contribute?


Make a fork!

Collaborating with Forks

To contribute to a repo you don’t have push permission for:

  1. Fork the repo to your own GitHub
  2. Clone the fork to your local computer
  3. Make commits (ideally on a branch)
  4. Make a pull request to the upstream repo

Learn more, including handy usethis shortcuts: https://happygitwithr.com/fork-and-clone

Exercise

In pairs, practice this workflow to make a PR to our example repo

References

Bryan, Jennifer. 2018. “Excuse Me, Do You Have a Moment to Talk about Version Control?” The American Statistician 72 (1): 2027. https://doi.org/10.1080/00031305.2017.1399928.