Why Use Git?

Article summary

Git Logo
I recently was asked to teach a workshop at Hope College on Git. I am jealous of the students that attended. Their curriculum includes things like unit testing and version control. Having the importance of source control shown to them so early is a major boon. Giving this talk got me thinking about why I prefer Git over other version control systems like SVN, Mercurial, Perforce, etc.

Why use Git?

1. It’s Multi-platform

Git was built for the Linux kernel, but supports other platforms. Head over to git-scm.com for download and install instructions. Most major IDEs and code editors have Git integration, making the git command line optional.

2. It’s Free

Git is open sourced under the GNU General Public License version 2. All the code is up on github. Not all the tools and integrations are free, but since I’m a command line junky, everything I need is free.

3. It’s Fast

Git was built from the ground up to scale, both in terms of number of participant and branches, as well as overall repository size. The classic example of a huge git-based project is the Linux kernel, which has thousands of contributors, thousands of commits, a the packed size of the current repository is over 100MB. Nothing that I’m working on can come close to those numbers, but it’s nice to know there’s room to grow.

4. It’s Distributed (for Offline Work)

Distributed version control systems like Git, Mercurial, and Bazaar have a clear advantage over their centralized counterparts: they allow users to work offline and continue committing to the repository in parallel to other developers, without getting blocked on acceptance of your commits. Even if you’re not stuck at the airport trying to write code, why tie any commands to network access and latency? Git puts your entire repository (history and all) at your fingertips.

As an example of when this helped us: A couple of years ago, one of our clients was hosting their repository privately on Github. Github went down for a big chunk of the day. Developers at AO were still able to share code and commits via a nice tool called bananajour. Once Github came back up, we could easily push our changes as if nothing ever happened. Try that with SVN!

5. Branching

Coming from an SVN background, the real beauty of Git is how it handles branches. We tend to work mostly on master, but anything that will not be finished by end of day generally gets moved to a separate branch. We keep master in a deployable state using branches for larger features or spikes. Git allows us to easily share branches, keep them up to date, and merge them back into master.

Along these same lines, git stash is amazing. It allows you to push your current changes onto a local stack to be popped off when convenient. You could accomplish the same thing with branches, but stashing doesn’t force you to actually commit any “in-progress” work.

Use it!

I could keep listing off reasons, but the short of it is: go try Git right now. I haven’t found anything better.