Git is a "distributed version control system" (DVCS). It's website is http://git.or.cz and you can read more about it on http://en.wikipedia.org/wiki/Git_%28software%29

There are precompiled versions available for Windows, Linux (via apt-get/yum/etc) and OS X, but if you want the most recent version, or to install it in a non-standard location, compiling it form source is actually very easy (on OS X at least).

This guide was done on OS X Leopard (version 10.5.3), but the steps are basically the same on Linux (just skip the bit about fink and Xcode), and other versions of OS X.

What you need

Basically compiling git requires gettext to be installed (or I got an error about _iconv or something). By far the easiest way to do this is to install "fink" (from http://www.finkproject.org/download/index.php ), and run

fink install gettext

You also need to have the Apple Developer Tools (Xcode) installed for cc/gcc/etc. They are on your Install DVD (or from the http://developer.apple.com/ ) site. There's plenty of guides on installing Xcode (if you are worried about space, you can probably uncheck most options in the installer, apart form the command line development stuff)

Getting git via git from git.git

Now, assuming you have a version of git already installed, goto http://git.or.cz/ and find the "git by git" section, and run the git clone command:

git clone git://git.kernel.org/pub/scm/git/git.git

If you don't have git, download the "Download GIT source package" and extract it (this will be a slightly older, but more stable version of the git source).

In a terminal (Terminal.app/iTerm), cd to where you cloned/extracted git:

cd ~/Downloads/git/

I install git it's own folder within /usr/local/ to keep things tidy (and to prevent 156 git-* commands being added to my path, although newer versions of git only put about 5 commands in $PATH). It's also far easier to remove or install new versions (as it's a single folder you can delete easily). If I install a stable version, it goes in /usr/local/git_1-5-6/ (for example), or from the git HEAD as /usr/local/git_head/

Oh, there is a "next" branch (which is basically the absolute-newest code, but is most likely to break), and the master branch (which is almost as new, but is less likely to break). If you want to compile the "next" branch, run:

git checkout -b origin/next

If not, skip that (master is checked out by default, and is what I'm using currently)

Note: run these steps as your regular user, apart from the last make install one.

Actual compiling

Now, the last few setups before actually compiling the code.. Create the ./configure script:

make configure

To make git get installed in a different path, use the --prefix= flag. This also checks you can compile things (it checks CC is installed and so on). It'll take a minute or two.

./configure --prefix=/usr/local/git_head

And now to actually compile the code! It'll take about 5 minutes, probably.

make

And finally, to copy the files into /usr/local/git-head. This needs to be done as root (thus the sudo command). This should only take a few seconds.

make install

That's it compiled!

Done.. almost

One last step is needed, so you don't have to type /usr/local/git_head/bin/git every time.

Either add /usr/local/git_head/bin/git to your path - in your ~/.profile, add:

PATH = $PATH:/usr/local/git_head/bin/

...or...

symlink the git binaries somewhere in your $PATH:

ln -s /usr/local/git_head/bin/git /usr/local/bin/git # for just git, which breaks git server apparently

or

ln -s /usr/local/git_head/bin/* /usr/local/bin/ # for just everything (only recommended for the git HEAD version, not the 1.5.6 stable release)