How to link RStudio Projects to GitHub Repositories

Step-by-step instructions how to setup an RStudio Project with a connected GitHub Repository

Tobias Byland
2022-11-02

.thumbnail { padding: 0px!important; margin: 0px!important; max-width: 10%!important; height: auto!important; vertical-align: text-top!important; }

It took me a while to figure out how to set it up so that an RStudio Project is linked to a GitHub repository, even though it is rather easy in the end.

So I wanted to write it down here - either for a forgetful future-me but maybe it can also help someone else in the same situation.

The necessary steps involved are:

  1. Create RStudio project
  2. Add version control to the project
  3. Create a GitHub Repository
  4. Link the project and the GitHub repository

And the step-by-step goes as follows:

1. Create an RStudio project

Create any kind of new RStudio Project, nothing special here.

2. Add version control to the project

Under Tools > Project Options > Git/SVN choose Git as version control system, and restart RStudio when prompted:

Afterwards Git should be selected as version control, and Origin set to ‘none’:

3. Create a GitHub Repository

Create a new GitHub repository, but do not include a readme, a .gitignore file or a license file!

This point is crucial as this would make it so that these files are available in the repository but not in your the RStudio Project and this difference in file will then create a bunch of complications which we then would need to solve. Better not go there in the first place.

So it should look like this when setting up the repository:

If done correctly you should be rewared with a screen with instructions needed for the final step:

And finally in order to link the Rstudio Project to the GitHub repository open a terminal window in RStudio (not the console) and enter the commands shown above:

There you go, from now on you can commit changes to Git and also push/pull to and from GitHub.