Introduction to Version Control

What is Version Control?

  • A tool that tracks changes to files
  • Records the changes you made, and the order in which you made them
  • Like the history of a page on Wikipedia
  • Or - like turning on ‘Track Changes’ in Word, but for code.

Why use Version Control?

A more efficient backup

  • Avoid multiple versions of same file

Why use Version Control?

Reproducibility

  • Access to a copy of every version of the code
  • Easy to replicate results from any paper!
  • Easy to share full copy of any version

Why use Version Control?

To aid collaboration

  • Easy to build on others’ changes
  • Share one version with collaborators whilst you work on another

How do Version Control Tools Work?

  • Start by storing the base version of the file
  • After that, only changes are stored
  • Like instructions for building lego

How do Version Control Tools Work?

  • Changes are separate from the document itself
  • Two users can make independent sets of changes
  • Creates two different versions of the document

How do Version Control Tools Work?

  • If no conflicts - merge changes
  • Two different sets of changes can be merged together onto the same base document

Version Control Systems

  • Git - overwhelmingly the most popular
    • GitHub, GitLab
  • Mercurial
  • Subversion

How can you use Version Control?

  • Command-line git
  • Standalone graphical user interface
    • GitHub Desktop
    • Git Kraken
    • Sourcetree
  • Built into most IDEs
    • Visual Studio Code
    • RStudio
    • PyCharm

Lesson Outline

We’ll cover how to use git to:

  1. Create a ‘repository’ and use it to track changes to files
  2. Review how your code has changed over time
  3. Recover old versions of files
  4. Back up your files to GitHub (or another remote repository!)
  5. Collaborate remotely and resolve conflicting edits to files