git

Oddly enough, while Time Machine was my favorite feature of Leopard before I installed it, I’ve not yet started using it, in large part because it doesn’t quite do what I want, and requires me to get one or more hard disks that, in total, are bigger than all the hard disks I need to back up put together.

Thanks to reddit, I came across git. Old news to some of you, no doubt, but … wow. Where has this been all my life?

What is git?

If you’ve got an hour, here’s Linux Torvalds talking about why he created git and a bunch of other stuff here:

The non-technical summary is this: git is a way of managing changes to the content of a directory, and sharing the changes with any number of other people. Rigorously.

The technical summary is this: git is fast, distributed, project-centric source control (vs. file-centric.)

For those who use conventional tools of this kind, such as CVS, Subversion, or Perforce — which are all in essence the same kind of tool — git is fast, easy to use, distributed, and content-of-the-directory-centric, vs. file-centric. In other words, the fundamental operation of CVS et al is to check out a file, modify it, and then submit the new file. Every operation needs to be thought of in terms of this fundamental operation. The fundamental operation of git is to make changes to the directory and then commit the changes.

Technically, this means that everyone works in their own branch, and merging branches is easy. Easier than simply performing ordinary changes within a single branch in a conventional SCM.

I’m no expert on SCMs, and most of my experience is with Perforce, but this is a typical operation:

  1. Decide what you want to do.
  2. Decide what files you’ll need to work with.
  3. Check out those files.
  4. Make your changes. Possibly check out more files. Possibly add new files.
  5. Commit the changes, carefully specifying every file you touched.

If you’re being especially responsible, you’ll diff every file you’re submitting to check change you’ve made.

Here’s what you do in git:

  1. Decide what you want to do … or not.
  2. Do it … or whatever you end up doing.
  3. Commit the changes. (You’ll be told what you changed, and can check the changes if you want.)

Installing git

You can download a pretty recent git package for OS X here. It installs very quickly (I’m a bit amazed that this command-line tool supposedly takes 100MB of hard disk space) and works flawlessly under Leopard.

There’s a quick guide to using git here. I had a test project set up in git in minutes, and quickly verified all the key functionality (making branches, switching between them, rolling back) worked exactly as expected.

Next Steps

I haven’t gotten into the distributed aspect of all this. (I haven’t quite figured out how to do it with my current setup.) Assuming all goes well — I’m sold. Not only on git as a version control system, but on git as a replacement for backing up in general. I could easily see git being run globally across your entire home directory in Leopard as an alternative to Time Machine, or on specific directories which need real configuration management.