Initial Setup on GitHub

Go to github.com and click on new “New” button next to “Repositories”.

In the next page, give your repository a name.

Names should:

  1. Be memorable.
  2. Be short.
  3. Not contain spaces.
  4. Avoid special characters, except _ and -.

After entering the name, click the green “Create repository” button.

That’s it! Your GitHub repository is now set up, and will be hosted at

https://github.com/your-name/your-repo-name

where your-name should be your username and your-repo-name should be the name you gave to the repository.

Initial Setup in RStudio Cloud

Go to rstudio.cloud and make sure you are logged in.

Start a New Project in RStudio Cloud

Click down arrow next to “New Project” button and select the “New Project from Git Repo” option.

Enter the URL for your GitHub repo, which again should be of the form

https://github.com/your-name/your-repo-name

Click OK, and RStudio Cloud will initialize the new Project with the files from the GitHub Repo.

Run Me Once Per Project Setup

Once inside the project, you need to run the following inside the Terminal pane once for each new project. The Terminal pane is in the same panel as the Console pane. Switch to the Terminal pane:

In the Terminal pane, type this (replacing you@example.com with your actual email address)

git config --global user.email "you@example.com"

and hit enter, then type this (replacing Your Name with your actual name)

git config --global user.name "Your Name"

and hit enter.

commiting, pushing, and pulling

committing a Change to the Local Repo

You are now ready to commit your first change to your local repository. To perform Git-related actions, click on the “Git” button below the “Debug” menu item:

To commit a change, click on the “Commit…” option in the drop-down menu.

This will bring up a GUI interface to Git and GitHub. There are three main sections of this interface:

  1. Top-left: The staging area, where all the files that have changed since your last commit are listed.
  2. Top-right: A textbox for you to enter your commit message.
  3. Bottom: An area showing the difference (called a diff) between the files for your most recent commit and the commit you are going to make now.

Click the checkboxes next to all of the new files in the repository, write a commit message, and click the “Commit” button.

pushing a Change to the GitHub Repo

At this point, you have committed your change to your local repository, which is stored on RStudio Cloud’s server. To make the changes show up on GitHub, you need to push your commit to GitHub.

To push a commit, click on the “Push” button in the top-right corner of the GUI for GitHub.

You will be prompted to enter your credentials:

  • GitHub username
  • GitHub password

and then you will receive a message telling you that the files have been successfully pushed to the GitHub repo:

Checking the status of Your Local Repo

At any time, you can check the status of your local repository by typing

git status

in the Terminal pane:

At this point, Git gave us the all-clear: our local repository agrees with the GitHub repository.

Checking the status of Your GitHub Repo

Similarly, you can check the status of the repository on GitHub by going entering the repository URL in your web browser:

We can see the local files from our RStudio Cloud repo have been pushed to the GitHub repo.

Continuing the commit-push Workflow

Adding Yet Another File

You can add a new file to your local repo, and ultimately the GitHub repo, by creating a new file like you usually would:

After you have saved the file (and given it a name), it is ready to commit. Make sure you save the file. If the text of the file name is red, this means the file has not been saved since your last change.

You can see that the file is ready to commit by running git status in the Terminal pane again.

Click on the GitHub icon to bring up the GitHub GUI:

You can see that the test-script.R file is ready to be committed. Click the checkbox to stage it for the commit, enter a new commit message, and click the “Commit” button:

Now push the change to GitHub, and you should get the message telling you everything went as-planned.

That’s it! Keep following this workflow, and you will get 99% of the benefits of a Version Control System with very little extra effort.

Steps so you don’t have to enter your username and password every time you push / pull from GitHub

One of the pain points of pushing and pulling from GitHub is the need to enter your credentials (username and password) each time that you do so. The following, taken from:

https://bren.zendesk.com/hc/en-us/articles/360015826731-How-to-connect-RStudio-Cloud-with-Github

walks you through how to set up RStudio Cloud so that it will store your (encrypted) credentials so that you do not have to re-enter them every time you push / pull.

In RStudio Cloud, inside the Project associated with your GitHub repo, go to Tools > Global Options... in the RStudio menu bar, select Git / SVN, and then click Create RSA Key...

A dialog box will pop up. You can click “Create” without entering a password.

Now click “View public key”.

Copy the public key to your clipboard.

Go to github.com, and click on your Profile Image in top right hand corner, and select Settings.

Select SSH and GPG Keys option from left menu.

Click the New SSH Key button.

Paste the public key in your clipboard into the “Key” text field.

Click the green “Add SSH key” button.

Navigate back to your RStudio Cloud project and go to the Terminal panel on the bottom pane of your window.

In the Terminal panel, type the following, replacing YourUsername and YourRepo with your Github username and Github repository name (as it is written in your Github repository URL):

git config remote.origin.url git@github.com:YourUsername/YourRepo

You’re all set!