What's version control?

Version control is a tool for managing changes to a set of files.

There are many different version control systems:

  • Git
  • Mercurial (hg)
  • CVS
  • Subversion (svn)
  • ...

Why use version control?

  • Better kind of backup.
  • Review history ("When did I introduce this bug?").
  • Restore older code versions.
  • Ability to undo mistakes.
  • Maintain several versions of the code at a time.

Git is also a collaborative tool:

  • "How can I share my code?"
  • "How can I submit a change to someone else's code?"
  • "How can I merge my work with Sue's?"

Git != GitHub

  • Git: version control system tool to manage source code history.

  • GitHub: hosting service for Git repositories.

How do we use version control?

Do some programming, then commit our work:

my_vcs commit

Program some more.

Spot a mistake:

my_vcs rollback

Mistake is undone.

What is version control? (Team version)

Sue James
my_vcs commit ...
... Join the team
... my_vcs checkout
... Do some programming
... my_vcs commit
my_vcs update ...
Do some programming Do some programming
my_vcs commit ...
my_vcs update ...
my_vcs merge ...
my_vcs commit ...


This course will use the git version control system, but much of what you learn will be valid with other version control tools you may encounter, including subversion (svn) and mercurial (hg).

Practising with Git

Example Exercise

In this course, we will use, as an example, the development of a few text files containing a description of a topic of your choice.

This could be your research, a hobby, or something else. In the end, we will show you how to display the content of these files as a very simple website.

Programming and documents

The purpose of this exercise is to learn how to use Git to manage program code you write, not simple text website content, but we'll just use these text files instead of code for now, so as not to confuse matters with trying to learn version control while thinking about programming too.

In later parts of the course, you will use the version control tools you learn today with actual Python code.


The text files we create will use a simple "wiki" markup style called markdown to show formatting. This is the convention used in this file, too.

You can view the content of this file in the way Markdown renders it by looking on the web, and compare the raw text.

Displaying Text in this Tutorial

This tutorial is based on use of the Git command line. So you'll be typing commands in the shell.

To make it easy for me to edit, I've built it using Jupyter notebook.

Commands you can type will look like this, using the %%bash "magic" for the notebook.

In [1]:
echo some output
some output

with the results you should see below.

In this document, we will show the new content of an edited document like this:

In [2]:
%%writefile somefile.md
Some content here
Writing somefile.md

But if you are following along, you should edit the file using a text editor. On windows, we recommend Notepad++. On mac, we recommend Atom

Setting up somewhere to work

In [3]:
rm -rf learning_git/git_example # Just in case it's left over from a previous class; you won't need this
mkdir -p learning_git/git_example
cd learning_git/git_example

I just need to move this Jupyter notebook's current directory as well:

In [4]:
import os
top_dir = os.getcwd()
In [5]:
git_dir = os.path.join(top_dir, 'learning_git')
In [6]:
working_dir=os.path.join(git_dir, 'git_example')
In [7]:

Solo work

Configuring Git with your name and email

First, we should configure Git to know our name and email address:

In [8]:
git config --global user.name "Giovanni1085"
git config --global user.email "gcolavizza@turing.ac.uk"

Initialising the repository

Now, we will tell Git to track the content of this folder as a git "repository".

In [9]:
pwd # Note where we are standing-- MAKE SURE YOU INITIALISE THE RIGHT FOLDER
git init
Initialized empty Git repository in /home/travis/build/alan-turing-institute/rsd-engineeringcourse/ch02git/learning_git/git_example/.git/

As yet, this repository contains no files:

In [10]:
In [11]:
git status
On branch master

No commits yet

nothing to commit (create/copy files and use "git add" to track)
In [ ]:
In [ ]: