What's version control?¶
Version control is a tool for managing changes to a set of files.
There are many different version control systems:
- Mercurial (
- Subversion (
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:
Program some more.
Spot a mistake:
Mistake is undone.
What is version control? (Team version)¶
|...||Join the team|
|...||Do some programming|
|Do some programming||Do some programming|
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 (
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.
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.
%%bash echo some output
with the results you should see below.
In this document, we will show the new content of an edited document like this:
%%writefile somefile.md Some content here
%%bash 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:
import os top_dir = os.getcwd() top_dir
git_dir = os.path.join(top_dir, 'learning_git') git_dir
%%bash git config --global user.name "Giovanni1085" git config --global user.email "firstname.lastname@example.org"
Initialising the repository¶
Now, we will tell Git to track the content of this folder as a git "repository".
%%bash pwd # Note where we are standing-- MAKE SURE YOU INITIALISE THE RIGHT FOLDER git init
/home/travis/build/alan-turing-institute/rsd-engineeringcourse/ch02git/learning_git/git_example 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:
%%bash git status
On branch master No commits yet nothing to commit (create/copy files and use "git add" to track)