COMP0233: Research Software Engineering With Python



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)

Graham Eric
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 either Windows, Mac or Linux, we recommend VS Code.

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 "Lancelot the Brave"
git config --global user.email "l.brave@spamalot.uk"

Additionally, it's also a good idea to define what's the name of the default branch when we create a repository:

In [9]:
git config --global init.defaultBranch main

Historically, the default branch was named master. Nowadays, the community and most of the hosting sites have changed the default (read about this change in GitHub and Gitlab.

Initialising the repository

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

In [10]:
pwd # Note where we are standing-- MAKE SURE YOU INITIALISE THE RIGHT FOLDER
git init
Initialized empty Git repository in /home/runner/work/rsd-engineeringcourse/rsd-engineeringcourse/ch00git/learning_git/git_example/.git/

As yet, this repository contains no files:

In [11]:
In [12]:
git status
On branch main

No commits yet

nothing to commit (create/copy files and use "git add" to track)