GitHub

Session 5

September 17, 2024

Review & Homework

  • If you turned an existing project into a git repo, how did it go?

  • Ways to create a git repo:

    • run git init from the command line inside of project directory
    • create a new RStudio project with “use git” checked
    • run usethis::use_git() in the R console in a RStudio project

Today’s goals

  1. Practice using git with RStudio
  2. Explore commit history
  3. Put a local repo on GitHub
  4. Use git push and git pull to synchronize with GitHub

Working with git in RStudio (Live Coding)

The most common git commands can be used with the RStudio GUI.

Sharing with GitHub

Connect With GitHub (Live Coding)

  • Set up your computer to “talk” to GitHub with steps in git_sitrep()
  • Connect your local git repo to a remote GitHub repo with use_github()
  • Explore the GitHub interface

Work With RStudio and GitHub (Live Coding)

  • Push local changes to GitHub
  • Pull GitHub changes to local

Ignoring files

  • If you enabled git with Rstudio or usethis, a .gitignore file was added for you, explore the contents
  • .gitignore also prevents files from being synced to GitHub
    • Use to keep large and non “diff-able” files local only to avoid GitHub file size limits
    • Use to prevent sensitive information from getting on GitHub (e.g. sensitive data, API tokens)
    • Cons: if ignored files are inputs, less reproducible and no backup on GitHub
  • If a file is already tracked by git, you can’t (easily) retroactively remove it from git history and GitHub.

Resources

Your Tasks

  • Put your research compendium on GitHub (e.g. with use_github()) and share the link in our Slack channel (if it can be made public)
  • Explore other research compendia shared in Slack

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.