What is Git and why use it?

If you’ve ever worked on a file called something like: report_v2_final_FINAL_reallyfinal.docx

…then Git is here to save your sanity.

Git is a tool that helps you:

Recommended video
Alice Bartlett explains Git for beginners:
Slides from her talk


Setting up RStudio, Git and GitHub

We’ll go step-by-step. You only need to do this once per computer.

Step 1 - Install R and R Studio

R has some great tools that help make using Git easier.

  1. Download R: https://cran.rstudio.com/

  2. Run the R installer – Keep all default settings.

  3. Download RStudio: https://posit.co/download/rstudio-desktop/

  4. Run the RStudio installer – Keep all default settings.

Step 2 – Install Git

  1. Download Git for Windows: gitforwindows.org

    • If you’re using a different operating system check out this resource on how to set up Git.
  2. Run the installer – Keep all default settings.

  3. Check it worked:

    • Open the command prompt (type cmd in the search bar on the taskbar)
    • Type: git --version
    • If you see a version number, you’re good. If not, try again or ask for help.

Step 3 – Create a GitHub Account

  1. Sign up for a (free) GitHub account (https://github.com/).
  2. Email your username to Katie () so I can add you to the WWS GitHub organization.

Step 4 – Tell Git Who You Are

Run these commands in RStudio (replace with your name and the email you used for GitHub):

#install.package("usethis") #only run once to install package
library(usethis)

usethis::use_git_config(user.name = "Your Name Here",
                user.email= "Your Email Here")

Step 4 - Connect RStudio to GitHub

We use a special “access token” (a long password) so RStudio can talk to GitHub.

  1. Now we’ll link your GitHub account to RStudio. To do this you need to get an access token from GitHub. This is a long string of characters (basically a password) that connects RStudio to GitHub.

Check if you already have one:

#install.packages(gitcreds) #run the first time 
library(gitcreds)
gitcreds::gitcreds_get()
## <gitcreds>
##   protocol: https
##   host    : github.com
##   username: katiewampler
##   password: <-- hidden -->

If your GitHub username shows up, you can skip ahead. If not:

Create a new token:

#install.packages(gitcreds) #run the first time 
library(gitcreds)

usethis::create_github_token()

This will open GitHub in your browser — scroll down, click Generate token (green button), and copy it.

Store your token:

This is important as once your token is generated you can’t get it from GitHub again.

gitcreds::gitcreds_set() 

When prompted for a password, paste your token. Done!

You’re All Set!

Now you can:

  • Save versions of your work without making endless copies

  • Restore old versions

  • Share work with others safely

  • Keep a backup online in case disaster strikes


More Resources