R has some great tools that help make using Git easier. It’s also a great tool for reproducible analysis.
RStudio provides a user friendly interface to using R.
Download R: https://cran.rstudio.com/
Run the R installer – Keep all default settings.
Download RStudio: https://posit.co/download/rstudio-desktop/
Run the RStudio installer – Keep all default settings.
Check installation
Open RStudio
Type the following in the console:
print("hello world")
Hit enter
Git is a tool that helps you:
Keep backups – If your computer is lost or damaged, you can get your files back from GitHub.
Track changes – See what you changed, when, and why. No more saving 10 versions of the same file.
Collaborate – Work with others without overwriting each other’s work.
Recommended video
Alice Bartlett explains Git for beginners:
Slides from her talk
Download Git for Windows: gitforwindows.org
Run the installer – Keep all default settings.
Check it worked:
In RStudo, go to the terminal tab
Type: git --version
If you see a version number, you’re good. If not, try again or ask for help.
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")
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!
Ensure it worked
Once you’ve got your token, you can run the following lines in R to check that your credentials are stored correctly:
gitcreds::gitcreds_get()}GitHub Desktop gives you a friendlier interface for managing files.
Download GitHub Desktop
Install and open the program.
Go to File → Options → Accounts and sign in to GitHub.
At OSU, the default is not the C Drive, which can create issues with file paths in R. We’ll go into more detail later, but we want to make sure you have a good folder to save your project to.
Navigate to: This PC → Windows (C:) → Users →
your username → Documents
If you don’t see the Documents folder, go to your
Documents folder in the Quick Access bar and copy it to
C:/Users/yourusername/
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
Happy Git and GitHub for the useR – excellent beginner guide
Git for Humans – Alice Bartlett – friendly talk