RStudio with GitHub

RStudio with GitHub

Hosting RStudio on GitHub is one of the most convenient things you can do with RStudio to keep a versioning of your files, to keep them synchronized among different computers, to share with co-workers, etc….

However, some of the repositories might be private and then it is a pain to keep typing the username/password combination in. I personally like about the authentification via ssh, so no user name is required for pulling or pushing, even in private repositories. This manual assumes, that you do not have a public ssh key, if you have one, you could simply register that to GitHub, see below.

First, you could start and globally register your user name and email to your local git by typing the following into the shell:

git config --global user.name "your.username"
git config --global user.email "your.email@somewhere.com"

Then you need to create your SSH key ( if you haven’t done before). If you have an ssh key, the following command will give you a warning that the file exists and that it would be overwritten, In that case you can cancel that and proceed without creating the key.

ssh-keygen -t rsa -C "your_email@example.com"

Next, the public key needs to be registered to the GitHub page. For that you first need to get your public key. This you can do either from with RStudio, there it is located in the Menu:  Tools -> Global Options -> Git/SVN -> View public key

or you can use your shell and type

cat ~/.ssh/id_rsa.pub

The public key should start with ssh-rsa or similar. You need to copy the whole sequence and paste it into your GitHub settings under ‘Settings -> SSH and GPG keys -> New SSH key’, give it a name and paste it. To check if the connection works, you can open your shell and type

ssh -T git@github.com

where you should get the message

Hi <user>! You’ve successfully authenticated, but GitHub does not provide shell access.

 

In the RStudio project you enter then as repository address the ssh address from your GitHub Repository, as can be found behind the ‘Clone or Download’ button. To get the ssh address you might still need to press ‘Use ssh’ in the upper right corner of the pop-up.

 

If the commited changes are too large to push intio the repositiory, the easiest is to go back to the previous head of the master branch by typing

git reset --hard origin/master

but before that, take care that you have a backuyp of all the last changes somewhere else, outside the git folder and copyt them after returning back to the it .

Leave a Reply

%d bloggers like this: