Go to github.com and click on new “New” button next to “Repositories”.
In the next page, give your repository a name.
Names should:
_
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.
Go to rstudio.cloud and make sure you are logged in.
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.
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.
commit
ing, push
ing, and pull
ingcommit
ting a Change to the Local RepoYou 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:
diff
erence (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.
push
ing a Change to the GitHub RepoAt 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:
and then you will receive a message telling you that the files have been successfully pushed to the GitHub repo:
status
of Your Local RepoAt 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.
status
of Your GitHub RepoSimilarly, 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.
commit-push
WorkflowYou 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.
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.