Installing Git on Mac OS X using Macports (in other words, the easy way)

Installing Git on Mac OS X using Macports (in other words, the easy way)

Posted 04/18/2011 - 15:43 by State68

This tutorial shows you how to install the Git version control system on a Mac. It assumes a little familiarity with the Command Line. If you don't know how to use the Command Line, then check out Addison Berry's excellent series of video tutorials over at lullabot.com: you can find the first one here and the rest here.

Once you're done installing Git, you'll need to learn a few commands to get Git doing what you want it to do. The video tutorials from peepcode.com are great, even if they do currently cost $12: if you can find a good, free resource that covers the fundamentals of Git then add a comment to this post.

If you're writing code of any variety you should be using a version control system, a piece of software that sits in the background and tracks the changes you make to your code. Whatever you're coding, a version control system will allow you to be more adventurous, as you won't be worrying about breaking stuff whenever you make changes.

There are a number of different version control systems available. Until relatively recently, Drupal.org used the Concurrent Versions System, but earlier this year switched to Git. Git has a number of advantages over CVS, including a cleaner syntax, a more active developer community, the facility to code collaboratively via GitHub and, if you are familiar with British English, an hilarious name.

So, if you want to contribute to the work that is done by the Drupal community at Drupal.org - writing modules or themes, or contributing patches to Drupal core, for example - you need to use Git. There are a number of different ways to install Git on the computer you use for development. I use a Mac, and this is the simplest installation method I've found:

  1. Get hold of a copy of Apple's XCode Developer Tools from here. You'll need to jump through a few hoops in order to get the download started, but it's a relatively straightforward process. Apple started charging for XCode as of version 4; Macports only requires the most recent release of version 3, which is - at the time of writing - still available at no charge. Once the XCode .dmg file is downloaded, run the installer.
  2. Download and install Macports from here. Macports is an easy to use system that allows you to install open source software from the command line. It's worth setting up on your Mac, since once it's installed you'll be able to use it to install other open source software. Unless you specificially know that you want to install Macports via a different method, download the .dmg file and install via that.
  3. With XCode and Macports installed on your Mac, run the following command from the command line to install Git:
    sudo port install git-core +bash_completion +doc +gitweb +svn

    Macports will go off and do its thing, configuring and installing all of the different components that are required for Git to work.
  4. Once Macports is finished you'll be returned to the command line. Type "git" and hit return. If you're given a load of information about the Git version control system then the installation worked and you're ready to start using Git to keep track of your code. If you don't get that information then it's likely that something went wrong with the install process; post a comment and I'll do my best to respond.
OK, maybe it's not the easy-ist way :)

There's been a couple of replies on Twitter that point out that a .dmg carrying a package installer for Git is available at the Git website. This is, of course, the case, and it's probably a more straightforward way of installing Git.

However, following the method outlined above is, in my opinion, the best solution in the longer term. With Macports installed on your Mac, you'll have easy access to a whole load of other open source software, and you'll be able to upgrade Git - and all the other pieces of software that you've installed via Macports, collectively known as "ports" - with two commands:

sudo port selfupdate
sudo port upgrade outdated

Posted by State68 on Mon, 04/18/2011 - 18:05