What is Version Control and why do I need it?#

The problem#

Unfortunately the situation below is more common than we like to admit.

Piled Higher and Deeper by Jorge Cham, http://www.phdcomics.com/comics/archive_print.php?comicid=1531

- “Piled Higher and Deeper” by Jorge Cham, http://www.phdcomics.com

It seems ridiculous to have multiple nearly-identical versions of the same document. Some word processors let us deal with this a little better, such as:

The solution#

Version control systems start with a base version of the document and then save just the changes you made at each step of the way.

A version control system is a tool that keeps track of changes for us and helps us version and merge our files. It allows you to decide which changes make up the next version, called a [commit], and keeps useful metadata about them. The complete history of commits for a particular project and their metadata make up a repository. Repositories can be kept in sync across different computers facilitating collaboration among different people.

  • Better kind of backup.

  • Version control is like an unlimited undo.

  • Review history.

  • Restore older file versions.

  • Ability to undo mistakes.

  • Maintain several versions of the code at a time.

  • Version control also allows many people to work in parallel.

Changes are saved sequentially#

You can think of it as a tape: if you rewind the tape and start at the base document, then you can play back each change and end up with your latest version.

Changes Are Saved Sequentially

Different Versions Can be Saved#

Once you think of changes as separate from the document itself, you can then think about “playing back” different sets of changes onto the base document and getting different versions of the document. For example, two users can make independent sets of changes based on the same document.

Different Versions Can be Saved

Multiple Versions Can be Merged#

Unless there are conflicts, you can even play two sets of changes onto the same base document.

Multiple Versions Can be Merged

Version control systems#

There are many different version control systems:

  • Git <<< We will use this VC system

  • Mercurial (hg)

  • CVS

  • Subversion (svn)

Important

Git != GitHub

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

  • GitHub: hosting service for Git repositories.