We’ll install the GitHub Desktop application first, as this should also install the most recent version of git to your computer (GitHub has a handy installation guide on their website). We’ll be using this application during the workshop, as it’s one of the most user-friendly ways to interact with your remote repositories.
You can download GitHub Desktop here, also in UWSP Self Service app installation center.
Installing the desktop application should have also installed the git program, but let’s double check just to be sure! For this, we have to go briefly to the command line/terminal. We can do this very easily by typing git –version into the Terminal, accessible through RStudio.
Check your git version by using the terminal in RStudio
If, for some reason, you don’t have git installed, there are several other options for doing so. See GitHub’s installation guide on their website and this guide for some helpful additional instructions.
Many (but not all!) of the options for installation are command line based, which can be intimidating if you’re not used to it. If you encounter any issues installing git, please contact Sam to help figure it out!
To use remote repositories stored on GitHub, you’ll need to create an account. It’s free and easy to do! My favorite GitHub learning resource, Happy Git with R, has some tips on how to create a good GitHub username.
We’re demonstrating an approach to configuring your git account using Rstudio, but there is also a very simple command line approach you can follow here, if you wish.
To do this in Rstudio with the usethis package:
{r} use_git_config(user.name = "your name", user.email = "name@email.org")
By this point, you have created your Github account and installed Git in your computer. These next steps allow your local computer to communicate with your remote Github account.
GitHub uses Personal Access Tokens (or PATs) in place of passwords for security reasons.
If you want to read more about why GitHub made this change, you can check out this blog post.
The instructions we provide here are for setting up PATs in R/RStudio, but you can do all of these tasks outside of R using GitHub and the command line. For additional alternatives (both in and out of R), check out the chapter on PATs in Happy Git with R.
First, install the usethis package, if you haven’t
already:
install.packages("usethis")
Next, run the following line of code:
usethis::create_github_token()
This will open GitHub at the PAT page. Follow the instructions and click “Generate Token.” Copy the access token that has been generated.
To save your PAT so you don’t have to enter it over and over again,
run the following using the gitcreds package:
gitcreds::gitcreds_set()
When asked to do so, paste your PAT and hit enter. You can also check
your saved PAT using gitcreds::gitcreds_get()
Voila! Your PAT is stored, and you may go about pulling and pushing as you please!
Here’s are some suggested materials about why we should use git and github.
Crystal-Ornelas, R., Edwards, B., Hébert, K., Hudgins, E. J., Sánchez-Reyes, L. L., Scott, E. R., … Braga, P. H. P. (2022, July 13). Not just for programmers: How GitHub can accelerate collaborative and reproducible research in ecology and evolution. https://doi.org/10.31222/osf.io/x3p2q
GitHub for supporting, reusing, contributing, and failing safely. https://www.openscapes.org/blog/2022/05/27/github-illustrated-series/
A Question of Code - Ep. 35: Do you git it? (What is version control?). https://open.spotify.com/episode/3TZRYdivudSmQiSL3bw4zF