Github Onboarding with RStudio

Author

Josef Fruehwald

Published

December 21, 2022

The target audience

I’m writing this primarily for students I’ll be teaching in Spring 2023 who I want to use Git/Github with Posit Workbench.

This tutorial is appropriate for:

Anyone using RStudio/RStudio Server/Posit Workbench/Posit Cloud

I will assume:
  1. Git is already installed and available.
  2. You have not already configured Git locally.
  3. You cannot access the terminal.

If item number 1 is not correct, or you want more detail on using Git and Github with RStudio, you should check out Jennifer Bryan’s much more extensive Happy Git and GitHub for the useR.

Item number 2 might be a strange assumption, but the Posit Workbench configuration I have access to actually does not allow opening a terminal.

Instruction boxes with should be done on github, and instruction boxes with should be done in RStudio.

Step 1: Create a Github Account

Go over to Github and create a free account.

As suggested in Happy Git Chapter 4, it would make sense to register an account username that aligns with your professional identity.

After you’ve created your free account, if you are affiliated with a university, I would also suggest applying for the education benefits here: https://education.github.com/. There are a few nice, but not mandatory, perks.

Step 2: Configure Git in RStudio

Now, you need to tell Git a little bit about yourself on the computer/server you’re using RStudio on.

Go To

Wherever you are using RStudio ( could be Posit Workbench, Posit Cloud, RStudio Server, or RStudio Desktop)

Then Go To

The Console (a.k.a the R Prompt)

A screenshot of RStudio. The console is in its default pane on the left hand side. An arrow has been drawn onto the screenshot pointing at the

The Console in RStudio is here.

Next, we need to tell the local version of Git who you are, specifically your username (which should match your Github username) and your email address (which should match the email address you registered for Github with).

,

In the code below, USERNAME should be replaced with your Github username and EMAIL should be replaced with the email you registered your github account with.

Run this in the R Console:
system('git config --global user.name "USERNAME"')
system('git config --global user.email "EMAIL"')

Step 3: Configure RStudio to Communicate with Github

In order to be able to push commits from RStudio to Github, you’ll need to set up secure communication between wherever you are using RStudio and Github. I’ll walk you through how to do this with SSH credentials. (See also Happy Git with R for personal access tokens via HTTPS).

RStudio Configuration

Go To:

The Tools menu, then Global Options

A screenshot of an RStudio session with Tools>Global Options selected

Then Go To:

Git/SVN from the left hand side option selector. Its icon is a cardboard box

A screenshot of RStudio's global options menu, with Git/SVN selected

Then Go To

Create SSH Key

A screenshot of the RStudio Git/SVN options menu, with Create SSH Key selected

Then

The default options should be fine to use. The passphrase here is for the ssh key. It should not be your Github password, or the password for logging into Posit Workbench or Posit Cloud. Once you’re ready, click Create.

Then

After creating the SSH key, you should see the option “View Public Key”. Click on it, and copy the text that appears.

This concludes everything necessary on the RStudio side of things. You should probably keep the session open so that you can come back to re-copy your public key.

Github Configuration

Now, you’ll need to go over to github to add the public key to your profile.

Go To

Your Github Profile Settings

Screenshot of a logged-in github session, with the user's profile setting selected

Then Go To

SSH and GPG keys from the left side menu

A screenshot of the github profile settings page with SSH and GPG keys selected

Then

Click on the New SSH key button

Screenshot of the Github SSH and GPG Keys settings, with New SSH Key selected

Then

Give this key an informative name so you can remember which computer it’s coming from.

Then

Paste the text you copied from RStudio into the Key box and click Add SSH Key.

Configured

Now, wherever you are using RStudio from should be able to push commits to your Github account.

Reuse

CC-BY-SA 4.0

Citation

BibTeX citation:
@online{fruehwald2022,
  author = {Fruehwald, Josef},
  title = {Github {Onboarding} with {RStudio}},
  series = {Væl Space},
  date = {2022-12-21},
  url = {https://jofrhwld.github.io/blog/posts/2022/12/2022-12-21_github-onboarding/},
  langid = {en}
}
For attribution, please cite this work as:
Fruehwald, Josef. 2022. “Github Onboarding with RStudio.” Væl Space. December 21, 2022. https://jofrhwld.github.io/blog/posts/2022/12/2022-12-21_github-onboarding/.