Tuesday, January 04, 2011

A Totally Barebones Guide to Getting Started with Git on a Mac

Disclaimer: This is a type first and work it out later guide created specifically to allow me to get collaborators started quickly. If you actually need to know about Git, check out the documentation! (You could do worse than Travis Swicegood's book, Pragmatic Version Control Using Git.)


Git is a version control system. (It's software.) It allows you to track the history of the project you're working on. In essence you store each and every change made to any of the project components. With this you are able to recreate the state that the project was in at any point in its development. It's easier to use than it sounds.

Using SOME kind of version control is vital. Absolutely guaranteed, you will repeatedly need to undo some balls-up or other, and without version control you are pretty much stymied. Using version control also aides in collaboration, our current endeavour.

Bottom line: always use version control.

At Noumenal we primarily use Git. The (main) other versions control systems you'll hear about are Mercurial and Subversion. (There are others.) It doesn't really matter which you use. Git and Mercurial are newfangled "distributed" version control systems. This doesn't matter either.

Installing & Configuring Git

First visit the OS X installer downloads page on Google Code. Click the "Download the packages here" link right below the Git logo.

Assuming you're running Snow Leopard, OS X 10.6 or greater, you'll need the .dmg file with the x86_64 in the name. (This is the 64 bit version for the Intel processor based Macs, which yours is.) Versions change but the latest as I write is git- Download this. Run the installer.

Now you'll need to open the Terminal application. (Welcome to my world.) Click on Spotlight (or hit command-space) and type 'terminal' to bring up the application. (It lives in /Applications/Utilities if you're concerned.) Once it comes up you can check that everything went to plan:

$ git --version
git version

The '$' is your prompt. This is configurable so it might be different. [What is the default bash prompt on OS X?] You type the suff in bold, exactly as is. You get the output below.

As a final step you just need to tell Git who you are and what your email address is. We're also going to set one other flag as you may not come this way again for a while:

$ git config --global user.name "Carlton Gibson"
$ git config --global user.email "support@noumenal.co.uk"
$ git config --global color.ui "auto"

Obviously put your own details in here.

One initially disturbing thing with the UNIX command line is that successful commands very often have no output. This is a virtue but it can take some getting used to. So how do we know our configuration commands worked?

$ git config --global --list
user.name=Carlton Gibson

You're done.