GitHub

Session 4

September 14, 2023

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. Learn how to tell git to ignore files
  4. Put a local repo on GitHub
  5. 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.

Ignoring files

  • If you created an RStudio project with git enabled, you should have a top-level .gitignore
  • Use this file (or create one) to stop git/GitHub from tracking…
    • large files, especially if not plain text
    • files with sensitive data
    • unnecessary files (e.g. .DS_Store)

Exercise

Modify .gitignore to exclude all files ending in .pdf from git tracking. Make a commit for this change

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

Resources

Homework

Put a (real) project repo on GitHub (e.g. with use_github()) and share the link on Slack (if it can be made public)

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.