Thursday, November 29, 2007

Installing Git on my Mac

Inspired by Dr Nic's post I wanted to install git on my Intel-based Mac. Why? There were two motivations - I frequently do work on the train or tram, and less often on planes, which is the reason Nic describes, but I also wanted to be able to commit mini-milestones on my local machine that I'm not really ready to commit to the "point of truth" on svn. This is the point where I reveal that I don't do all of my programming test first, but that's a longer thread. Suffice it to say that there are periods where I need to work to get the test coverage back over the threshold (currently set to 99.2%) and I don't want to commit to svn until the test coverage is back there.

I installed git-core from MacPorts, but when I ran git-svn I didn't have a "clone" command, which is what all the cool kids are talking about. I'm still not sure that I know precisely why that was the case, but in poking around on the web I found a few places with installation instructions, and eventually things were working, so I'll add what I did to the pool (my main motivation is letting you know the problem I was trying to fix though).

  1. Followed the instructions from to install the latest version of Git from source

  2. Re-installed subversion using the package from Why? Because the last step in the previous instructions (setting the PERL5LIB) didn't help, and I couldn't find the svn-perl libraries anywhere. The instructions on were helpful. After the subversion installation I had a directory /usr/local/lib/svn-perl, which did the job.

  3. Added export PERL5LIB='/usr/local/lib/svn-perl' to my .profile

  4. Added /usr/local/git- to PATH in my ,profile (early on, to make sure git was found here first)

  5. When I tried git-svn I got an error concerning Term::ReadKey when perl tried to prompt me for a password. I tried to install Term::ReadKey from CPAN interactively (sudo perl -MCPAN -e 'shell'
    , then 'install Term::ReadKey', but got "Can't exec "./make": No such file or directory at /System/Library/Perl/5.8.6/ line 4566.". The answer was to change directory to ~/.cpan/build/TermReadKey-2.30 and execute the following commands: sudo perl; sudo make; sudo make test; sudo make install. Now I have the Term::ReadKey module installed!

  6. When I tried to 'gitify' after that, I got this message : "error: More than one value for the key svn-remote.svn.fetch: :refs/remotes/git-svn". This seems to have been caused by previous failed attempts - removing the xxx.git file and running 'gitify' again seemed to work.

For people like me who are less than clear about the result, here's what you get:

  1. A copy of your project in '../project_name.git'. This is your git working directory.

  2. Your repository is in .git in the git working directory.

  3. Change into the git working directory and start doing your stuff

  4. You'll probably find these commands useful:

    • git status : tells you what's uncommitted

    • git add : adds a new file to version control. "git add *" seems to do everything you'd want :-)

    • git checkout -f : reverts local changes

    • git commit -a : commits any modifications (but not new files) to the repository

    • git-svn rebase : merge svn changes into your git repository

    • git-svn dcommit : commits all your changes back to svn

And if I'd known it was going to be this hard when I started, I wouldn't have.