Connecting our local repository to GitHub

Our project is fully version controlled so we have access to a detailed history of every change we’ve ever made to it. This is a great first step but all of this only exists on our own computers at the moment.

It’s time to upload our project to GitHub!

Putting your code on GitHub confers a number of benefits:

Creating a new repository on GitHub

At the Create a new repository screen, give your repo a name and click Create Repository. In this case only, when you didn’t start by creating a repo on GitHub but want to push from an exisiting local repository for the first time like we are doing now and like you would to upgrade your old projects, do NOT select ‘create a README file’ but directly ‘Create repository’.

The Quick Setup screen gives sets of git commands that can be used in various circumstances.
First, make sure you select the SSH tab (the url shown in the blue box should start with git@github.com).

We are then interested in …or push an existing repository from the command line. Copy these commands to the clipboard using the copy button on GitHub.

In RStudio, navigate to the git tab and click on More -> New terminal


Paste the git commands into the Shell and press Enter to execute them. Given this is your first push, you may be asked again to authenticate your identity by entering the password of your SSH key

and/or prompted with such sentence in the terminal:

Are you sure you want to continue connecting (yes/no/[fingerprint])?

to which you should answer yes


Warning for Windows OS with RStudio > 2022.12.0 If you get an error saying you do not have a SSH key in the appropriate location, this is due to a known bug in the RStudio / Git bash interaction which we expect to be eventually resolved with updates. A temporary solution is to open the Windows Power Shell instead of Git Bash as terminal within RStudio: for this, go to RStudio -> Tools -> Global Options -> Terminal -> New terminals open with -> choose Windows Power Shell -> Click Apply -> close the panel -> Complete the steps above (i.e. paste or type the commands presented by your new GitHub repo) -> change back the default terminal within RStudio to Git Bash.


Finally, confirm that the project has been uploaded to your GitHub profile (you may need to refresh your GitHub page).