Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
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.
This example is done on RStudio Server, but the same procedure can be used for RStudio desktop. Git or similar needs to be installed first, which is straight forward to do.
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).
Click, View public key, and copy the displayed public key.
git config --global user.email "mail@ewenharrison.com" 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.
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 git@github.com:ewenharrison/test.git git pull -u origin master git push -u origin master
Clone an existing GitHub project to new RStudio project
In RStudio, click New project as normal. Click Version Control.
git config remote.origin.url git@github.com:ewenharrison/test.git
Interested in international trials? Take part in GlobalSurg.
R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.