Skip to content
R for the Rest of Us Logo

Push an RStudio Project to a GitHub Repository

This lesson is locked

Get access to all lessons in this course.


Click on the transcript to go to that point in the video. Please note that transcripts are auto generated and may contain minor inaccuracies.

Your Turn

  1. Open the local-first project you created previously

  2. Push your local-first project to GitHub using the use_github() function from the usethis package

Have any questions? Put them below and we will help you out!

You need to be signed-in to comment on this post. Login.

I set my github PAT up without a problem a while ago but returning to this (and catching up on some long-delayed lessons here) I can't connect to github. I get the error message "Error: GitHub PAT must have one of these forms:

  • 40 hexadecimal digits (older PATs)
  • A 'ghp_' prefix followed by 36 to 251 more characters (newer PATs)"

When I check on github the PAT is still the one I set up, so I'm not sure how to fix this.

Can you try just creating a new PAT and seeing if that works?

That worked!


Hi Dave, I am trying to push a local R project to Github. My goal is to push this R project currently located on my PC only to Github, and then pull it to my MacBook. I believe I have set up PAT correctly in R Studio on both the PC and the MacBook.

I used: usethis::use_github()

I got the error (without showing other actions that were actually successful): Error in libgit2::git_remote_push : failed to receive response: A security error occurred

Googling the error message hasn't gotten me anywhere. Could you share insights on what the "security error" might have been?

That's a new one for me! Quick question: did your R project show up on GitHub?

It did, but it's empty. That is, only the repo's name is there. In case helpful, below is the entire return in R studio after I ran usethis::use_github():

ℹ Defaulting to 'https' Git protocol ✔ Setting active project to 'C:/Users/Yuan.Liu/Desktop/EcoMon2019SealScat' ✔ Creating GitHub repository 'yliu-atwork/ProjectName' ✔ Setting remote 'origin' to '' ✔ Pushing 'main' branch to GitHub and setting 'origin/main' as upstream branch Error in libgit2::git_remote_push : failed to receive response: A security error occurred ✔ Opening URL ''

David Keyes

David Keyes

March 1, 2023

Are you sure you're working in a project? This shows what you should see:

Morning Dave! Yes, I am in my project. Also, I set up a test R project on my PC and I failed to push that to Github as well (same error message). However, I am able to do it from my MacBook. Strange stuff! I reached out to our IT Helpdesk in case it's a security thing of my work PC. I'll share any follow-ups (may take a while). Meanwhile, please let me know if you think there is anything else I could try. Thank you!

Zain Asaf

Zain Asaf

June 11, 2023

Hi David and Charlie, I am working on something from week 10. I wanted to post the gist for the code as I am getting an error message. I wanted to post the code to an existing project that I have called "zain_rin3-project' However, when I attempt to push the project to github, I get the following error message "Error: Repo 'zainasaf/zain_rin3-project' already exists on ''. I assume it is possible to push the code to an existing project, and we do not have to create a new project in github each time we post new code. Is there a step that I am missing ?

David Keyes

David Keyes

June 12, 2023

I believe this is the same issue that we experienced before when we had our call together. Can you please record a quick video to show what you're seeing?