Collaborating with GitHub

Objective

Learners will fork and clone a repository on GitHub and use branches to open pull requests.

Lesson Outline

  • Review Homework:

    • Anyone put a repo on GitHub? Any difficulties encountered?
  • Live Coding: Collaborating with GitHub

    • Share a repo with everyone & have everyone clone w/ RStudio
    • Ask 1 (one) volunteer to make a change and practice commit + push
    • Instructor makes commit + push, volunteer pulls
  • Live Coding: Merge conflict

    • Instructor makes commit to README and pushes to GitHub
    • Volunteer makes commit to the same line of README and pushes without pulling first
    • Should error for volunteer
  • Slides: Resolving merge conflict

  • Live Coding: Resolve merge conflict

    • Try following the hints in the error and pull
    • New error about divergent branches
    • Then have everyone set git config pull.rebase false
  • Working on branches (slides)

  • Live Coding:

    • Make a branch with your name in RStudio
    • Add your name to README and commit
    • Switch between branches and see the file change in RStudio AND in File Explorer / Finder
    • Push & see branches on GitHub
  • Pull Requests (slides)

  • Live Coding:

    • Have everyone make a PR to add their name to the README
    • Demo merging one or two & ask volunteer to resolve any merge conflicts
  • Forks (slides)

    • Discuss when you would work on a branch of a fork vs. working in a branch but on the same repo
  • Live Coding:

    • Have students create a fork of a second example repo and clone their fork
    • In pairs, have them practice making a branch, making changes, commit + push, and make a PR on GitHub
  • Homework:

    • Maybe try cloning a repo that you don’t have permission to push to to see what happens

    • Try using usethis::pr_finish() on a branch that was already merged on GitHub and take note of what it does

Citation

BibTeX citation:
@online{scott2024,
  author = {Scott, Eric and Diaz, Renata and Guo, Jessica and Riemer,
    Kristina},
  title = {Collaborating with {GitHub}},
  date = {2024},
  url = {https://cct-datascience.github.io/repro-data-sci/lessons/6-github-collab/notes.html},
  doi = {10.5281/zenodo.8411612},
  langid = {en}
}
For attribution, please cite this work as:
Scott, Eric, Renata Diaz, Jessica Guo, and Kristina Riemer. 2024. “Collaborating with GitHub.” Reproducibility & Data Science in R. 2024. https://doi.org/10.5281/zenodo.8411612.