Chapter 9 Git and Github

Seb James taught this class over the last three years - thanks Seb! *

9.1 Motivation

Git is an incredible common tool among software developers and computer scientists. It has powerful functionality for coordinate code projects across many people. As a core data science tool I want everyone on the course to have had some exposure to it, and to recognise the key concepts (as well as the value it has). We will not be using the full functionality in the course.

9.2 Before the class

Create an account on, if you don’t already have one.

Install git on your machine.

Until you do that you DON’T have the git features enabled in RStudio.

9.3 Accessing git

If you have RStudio you can access git using point and click (top right), or via the terminal (the tab next to Console on the bottom right).

Outside of RStudio:

  • Students using Windows can install: Once installed they should be able to open a git bash window and type git --version
  • Students on a Mac will have git if they install ‘Xcode’ and ‘Command line tools for Xcode.’They can test by opening a terminal and typing git --version

9.3.1 Trouble shooting

We are aiming to install git, and mamage syncing with github via RStudio. For these three components, different things on different types of computer can successful coordination, so there is some irreducible complexity in getting your set up working. The notes below should help for 90% of issues, and hopefull you only need to solve these installation issues once for mac, you may need install homebrew to install git

On mac, change the default terminal to BASH, install homebrew:

In the terminal:

  • Cmd + space
  • Type terminal
  • Press enter
  • In the terminal type, chsh -s /bin/bash
  • Enter password (this won’t show as you type) and press enter
  • Close the terminal
  • Reopen it
  • To install git, type brew install git

Through system preferences:

  • Click on system preferences
  • Click on ‘Users and groups’
  • Press ctrl + your user
  • Click advanced options
  • Change ‘login shell’ to /bin/bash
  • Open the terminal (instructions above)
  • To install git, type brew install git To configure git with RStudio


  • Click tools
  • Click global options
  • Click Git/SVN
  • If git executable says ‘None,’ browse to where git is installed on your laptop
  • Click ok
  • In the RStudio terminal:
  • Type git config GitHub_USERNAME
  • Type git config GitHub_EMAIL For errors around ‘fatal: authentication failed’

  • Click on your profile in the top right
  • Select settings
  • Scroll to select developer settings on the left hand side
  • Click Personal Access Tokens
  • Click Tokens (classic)
  • Click Generate new token
  • select Generate New token (classic)
  • Give your token a name (e.g. ‘personal’)
  • Change the expiration to ‘No expiration’
  • Select repo
  • Scroll to generate token and select
  • Copy the token (once you leave this page you will lose this token forever)
  • Go back to RStudio
  • Try to push the commit
  • Enter your username
  • When prompted to enter password, enter the token you copied NOT your password
  • Press ok

9.4 Essential terminology

repo: “repository.” A set of files which are in the same project and for which version control using git is appliued

remote and local: repositories can be on your computer (local) or online, e.g. on (remote)

clone: make a copy of a repo

branches: repos can exist in different versions, “branches”

Other terminology, commit, merge, rebase, push/pull: see below

Nikki Siapno “Git workflow”

9.5 Checklist

Git and github are fundamental tools which will be relevant for collaborating on reliable computational projects, but it is not essential you master the full range of capabilities they offer for this module.

By the end of this class you should

  • have a github account
  • installed git on your local machine
  • understand why git is useful for code projects
  • recognise the essential terminology: repo/repository, remotes and local, clone, branches, commit, merge, rebase, push/pull

9.6 Resources

You can RTFM

Or you can try one of the following tutorials, they all teach the same thing but in slightly different ways