In order to work with code that is stored on Github in R Studio we need to ‘clone’ the relevant repository. ‘Cloning’ a repository means creating a copy on your local machine that so you can run and edit the code in it!

To clone a repository, follow these steps:

  1. First we need to generate a ‘personal access token’.

    1. To do this go to Github’s token generator page and select ‘Generate new token’ then ‘Classic’.
    2. You can then put anything in note, but make sure the gist, repo, user and workflow boxes are checked and click generate token.
    3. Make sure you copy and paste this token somewhere safe as you won’t be able to see it again! We will need it later on and a lot in future
    • Unless you have set it not to, eventually this token will expire will expire and you will need to create a new one.
  2. Next obtain the address of the repository you want to clone. This can be found on the repository page on github by clicking the green “<> Code” button (it is usually the URL of the repo with “.git” at the end).

  3. Next, in R Studio go to ‘File > New Project > Version Control > Git’ and paste in the address from the previous step. Then click ‘Create project’.

  4. If prompted enter your Github username but instead of our password we need to use the token we generated in step 1.

  5. You have now successfully cloned a repo into your R Studio. You should now be able to access the git tab in the top right window.

To make changes to the code follow the steps on the “How to edit Github code” page.