Git Part 1: Use version control (for everything you can)

28th May 2020

In the strange limbo of lockdown, I’ve been reflecting on the things I wish I’d known when I started out as a developer. There’s a lot that falls into that category: Libraries that could have saved me hours of frustration, smarter ways of working, even software.

One of the most important differences in how I work now is in the use of version control.

What is version control?

To put it simply, version control is a system that lets you track changes to files (i.e. the different versions of each file). This is generally done on a per project basis, so you’ll track a folder as a project (called a repository).

Why is this a good idea?

Any project, particularly one involving code, can suddenly take a wrong turn, and you’ll find yourself wishing you could go back to a previous version where it was working. With version control, you can switch to any previous version without having to worry (a real step up from having my-file-v2-final.php in a folder somewhere).

Version control is also great for collaboration. You can see who has worked on a project and what they’ve done, and you can even merge together different versions to combine everyone’s work quickly and easily.

What are my options?

There are several different version control systems, with a variety of features.

  • Git
  • SVN (Subversion)
  • Hg (Mercurial)
  • Perforce (Helix Core)

My system of choice is git. It’s very popular and well supported.

What can you do with git?

Git gives you a number of superpowers, and after using them on a project you’ll find it hard to go back.

  • Track milestones and revert – easily track when things are working, and roll back easily if your changes break something.
  • Feature branches – work on multiple features at once on different copies of the code, and easily merge them together once they’re ready to go.
  • See a project’s history – see who wrote each line of code, when they did it and how the project’s grown.
  • Merge changes – two different versions of a file become one, bringing in the changes made to both without losing work.
  • Remotes – Keep a copies of your code online or on multiple devices and easily keep each up to date with your changes.
  • View differences – View a list of differences between versions of a file or project.

Getting started with git

If you’re using Linux or OSX then you probably already have git installed, however it’s a good idea to get the latest version. If you’re on Windows then you’ll need to install it to use it.

The official website has instructions on how to install git, but you can also use other options such as package managers like Homebrew or Chocolatey.

In our next post we’ll look at how we can use version control in a project.