Introduction to

Version Control

Mike Irvine

21 November, 2024

What is a Version Control System?

What is a Version Control System?

  • Rational way of dealing with multiple people working concurrently on same files
  • Tracks who makes changes, when they made changes, and what they changed
  • Maintains multiple versions of the same project

Why should we use version control?

Why should we use version control?

Consider this familiar situation…

Why should we use version control?

Often arising from this situation…

Why use version control?

Have you ever:

  • Made a change to code, realised it was a mistake and wanted to revert back?
  • Lost code or had a backup that was too old?
  • Had to maintain multiple versions of a product?
  • Wanted to see the difference between two (or more) versions of your code?
  • Wanted to prove that a particular change broke or fixed a piece of code?
  • Wanted to review the history of some code?
  • Wanted to submit a change to someone else’s code?
  • Wanted to share your code, or let other people work on your code?
  • Wanted to see how much work is being done, and where, when and by whom?
  • Wanted to experiment with a new feature without interfering with working code?

Which software to use?

Which version control system to use?

  • For documents might consider Google docs, Word online, Overleaf,…
  • For code and software the overwhlemingly popular choice is Git
  • Git is open-source, free, and integrates nicely with Posit Studio, VS Code, and other IDE
  • Does require use of terminal and can have a steep learning curve

Git versus GitHub

  • Git is a version control system originally developed by Linus Torvalds that lets you track changes to a set of files
  • GitHub is a web-based hosting service for Git repositories which allows you to create a remote copy of your local version-controlled project. This can be used as a backup or archive of your project or make it accessible to you and to your colleagues so you can work collaboratively.
  • Github provides lots of collaborative and project management tools along with managing project versions. Git is the tool to keep track of changes and push those changes to Github

Some terminology

  • Repository - or repo is a collection of files together with a hidden folder used by git to track any changes to the files. A repo can be remote, where it exists in the cloud or on another computer that can be accessed by multiple users or it can be local where it exists only on one computer
  • Clone - The process of taking a repo stored elsewhere and downloading it onto a local machine
  • Push - Add any changes that have been made to a remote repository
  • Pull - Update a local repo with changes that have been made on the remote repository

Using Git

Using Git

  1. You create/delete and edit files in your project directory on your computer as usual (saving these changes as you go)
  1. Once you’ve reached a natural ‘break point’ in your progress (i.e. you’d be sad if you lost this progress) you stage these files
  1. You then commit the changes you made to these staged files (along with a useful commit message) which creates a permanent snapshot of these changes
  1. You keep on with this cycle until you get to a point when you would like to push these changes to GitHub
  1. If you’re working with other people on the same project you may also need to pull their changes to your local computer

Git playground

Wrapping up

Git tips

  • Generally speaking you should commit often (including amended commits) but push much less often.
  • If you don’t want to track a file in your repository (maybe they are too large or transient files) you can get Git to ignore the file
  • Adding to a repository like Github means you can always trash and start over…

Further Git resources

Questions?