Version Control with Git

Version control is the best way of collaborating on any coding project. It keeps a snapshot of all changes ever made by both parties, and merges these changes gracefully. Now I know what some of you may be thinking: “What if I’m going to be the only one working on a project? What if I don’t want anyone else to see my code? Why not use a service like Dropbox instead if I want a backup?”

To quote a comment by user si618 on stackoverflow:

Have you ever:

  • Saved a change to a file, realized it was a mistake and wanted to revert back?

  • Lost files 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?

  • Needed to find a particular change that 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?

If any of these things apply to you, you should be using version control. In particular, I find it indispensable to go back and look at every change I’ve ever made to a file, pinpoint where a bug cropped up in code, and simply be able to be able to experiment around or delete files with no consequences whatsoever.

Version control is the lab notebook of the digital world: it’s what professionals use to keep track of what they’ve done and to collaborate with other people. Every large software development project relies on it, and most programmers use it for their small jobs as well. And it isn’t just for software: books (like this one), papers, small data sets, and anything that changes over time or needs to be shared can and should be stored in a version control system. It’s a programming standard, and every project should be using it.

Prerequisites

In this lesson we use Git from the Unix Shell. Some previous experience with the shell is expected, but isn’t mandatory.

Getting ready

Nothing to do: you’re ready to go!

Here’s the scenario for our lesson:

Wolfman and Dracula have been hired by Universal Missions (a space services spinoff from Euphoric State University) to investigate if it is possible to send their next planetary lander to Mars. They want to be able to work on the plans at the same time, but they have run into problems doing this in the past. If they take turns, each one will spend a lot of time waiting for the other to finish, but if they work on their own copies and email changes back and forth things will be lost, overwritten, or duplicated. They are going to learn version control to solve these problems!

Topics

  1. Automated Version Control
  2. Setting Up Git
  3. Creating a Repository
  4. Tracking Changes
  5. Exploring History
  6. Ignoring Things
  7. Remotes in GitHub
  8. Collaborating
  9. Updating forked repositories

Other Resources