Version control has become essential for me keeping track of projects, as well as collaborating. It allows backup of scripts and easy collaboration on complex projects. RStudio works really well with Git, an open source open source distributed version control system, and GitHub, a web-based Git repository hosting service. I was always forget how to set up a repository, so here’s a reminder.
Setup Git on RStudio and Associate with GitHub
In RStudio, Tools -> Version Control, select Git.
In RStudio, Tools -> Global Options, select Git//SVN tab. Ensure the path to the Git executable is correct. This is particularly important in Windows where it may not default correctly (e.g. C:/Program Files (x86)/Git/bin/git.exe).
Now hit, Create RSA Key …
Click, View public key, and copy the displayed public key.
If you haven’t already, create a GitHub account. Open your account settings and click the SSH keys tab. Click Add SSH key. Paste in the public key you have copied from RStudio.
git config --global user.email "[email protected]" git config --global user.name "ewenharrison"
Use your GitHub username.
Create New project AND git
In RStudio, click New project as normal. Click New Directory.
Name the project and check Create a git repository.
Now in RStudio, create a new script which you will add to your repository.
You have now committed the current version of this file to your repository on your computer/server. In the future you may wish to create branches to organise your work and help when collaborating.
Now you want to push the contents of this commit to GitHub, so it is also backed-up off site and available to collaborators. In GitHub, create a New repository, called here test.
git remote add origin https://github.com/ewenharrison/test.git git config remote.origin.url [email protected]:ewenharrison/test.git git pull -u origin master git push -u origin master
You have now pushed your commit to GitHub, and should be able to see your files in your GitHub account. The Pull Push buttons in RStudio will now also work. Remember, after each Commit, you have to Push to GitHub, this doesn’t happen automatically.
Clone an existing GitHub project to new RStudio project
In RStudio, click New project as normal. Click Version Control.
git config remote.origin.url [email protected]:ewenharrison/test.git
Interested in international trials? Take part in GlobalSurg.