Connect RStudio to GitHub
Connecting to GitHub
In order to interact with GitHub via RStudio, you need to authenticate yourself. That is, you need to prove you are the owner of your GitHub account. When you log in to GitHub from your browser, you provide your username and password to prove your identity. But when you want to push and pull from your computer, you will need to use a personal access token (PAT).
This is how R may try to tell you that it wants to see your PAT:
remote: Support for password authentication was removed on August 13, 2021. Please use a personal access token instead.
remote: Please see https://github.blog/2020-12-15-token-authentication-requirements-for-git-operations/ for more information.
fatal: unable to access “uni-mannheim-qm-2025/week01…” : The requested URL returned error: 403
This guide provides step-by-step instructions to set up Git and GitHub with RStudio. Herein, we illustrate two alternatives to use your PAT to authenticate RStudio with GitHub.
Step 1: Install Git
First, install Git following this guide.
Step 2: Create a token
Option A: via github.com
Then, log onto your GitHub account and generate a personal access token: GitHub → User icon → Settings. In Settings, navigate to → Developer settings → Personal access tokens and choose → Tokens (classic). Then click on Generate Token → *Generate new token (classic) as seen in the picture below. → Personal access tokens → Tokens (classic)

Now you have to put set up your token. Under Note you label or name the token to be generated. Set the Expiration date, e.g. until the end of the semester using Custom or, if you do not want the token to be expiring, choose No expiration.
Next, under Select scopes check
- repo
To finish, click Generate Token at the bottom of the page.

Congratulations, you have now generated a token! It should look something like this: ghp_a1B2c3D4e5F6g7H8i9J0klmnopqrstUvWxY. Make sure to save it somewhere safe,
e.g. encrypted in a password manager.

Option B: via RStudio
Run these lines in the console (left bottom pane):
install.packages(c("usethis"))
usethis::create_github_token()
This will open a new page on Github in your browser, where you’ll need to select the validity period of your PAT, Expiration. You may want to set it for a longer period of time then 30 days, the default, if you want to deal with this issue less frequently.
Click on Generate Token at the bottom of the page.
Next page will give you the PAT. It will be a long string and will look something like this: ghp_Kt33T3rXI1m4a9vxpBU0ngRU0. Don’t close this page yet! You’ll need this token, so copy it.
Step 3: Use a token to connect RStudio to GitHub
Now that you have the PAT, you need to tell it to R. Up until now, it’s only there on Github and R does not know your PAT. Here’s how you tell the PAT to R:
Option A: Package ‘credentials’
Run the following code with R:
install.packages("credentials")
library(credentials)
set_github_pat()
Respond to the prompt with your personal access token (PAT).
If successful, your initial (and subsequent) calls will look like this:
set_github_pat()
That’s it. You should be able to get your Github repo onto your local Rstudio now!
Option B: Package ‘gitcreds’
Open RStudio and run the following code to install and employ the gitcreds package to authenticate with GitHub.
install.packages("gitcreds")
library(gitcreds)
gitcreds_set()
After executing gitcreds_set() you will be prompted to input your token.
install.packages("gitcreds")
> gitcreds::gitcreds_set()
? Enter password or token: ghp_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
-> Adding new credentials...
-> Removing credentials from cache...
-> Done.
If you run gitcreds_set() after you have already successfully set it up, you are provided three options: (1) to abort, (2) to replace your credentials or (3) display your current token.
Update an expired PAT
At some point, your PAT will expire and you will need to update it. It’s very easy to do: First, follow the same steps as above to generate a new PAT (see step 2).
Then run the following code to save (aka cache) the token in R. Add the force_new = TRUE argument to rewrite the stored, expired, PAT.
credentials::set_github_pat(force_new = TRUE)
You’re done.
Step 4: Embed a repository as a R project
Go to the course repository https://github.com/uni-mannheim-qm-2025 and copy the link of the respository.

Troubleshooting if you cannot locate the repository.
Next, open RStudio. Navigate to *File → *New Project. Now, choose Version Control → Git and paste the Repository URL.

Step 5: Connect Git in RStudio with your GitHub account
In the terminal, type the following commands and replace your username and email with the name and email you used to create your GitHub account accordingly:

git config --global user.name "your username"
git config --global user.email "your_email@example.com"
If successful, your terminal should look similar to the screenshot below.

Next steps: Pull, Commit, Push
- Pull: Download files from the repository
- Commit: Save changes
- Push: Upload saved changes to the repository
Try it!
- Open the file
test.Rmd - Make a small change
- Commit the change by checking the edited file and describing the changes in the Commit message, then Push to upload the commit

