Git on Mac OS X

Nov 18, 2008 Git Mac OS X

Okay, forget what I just said about svn on OS X. This week, I'm moving one of my projects into a private repo on github. Why? Well, obviously because it's the new hotness. Because all the kids are doing it? Actually, the answer is "why not?". It can't hurt to learn another source control tool, and I've heard enough good reviews from friends to make me want to see what all the fuss (or lack thereof) is about.

The first step is to set it up locally, though. Start by downloading git: http://git-scm.com/download

If you really want to compile it yourself (and normally I would), there are some fairly verbose guides here and here.

I found this installer first though - it worked without a hitch: git-osx-installer

Pop open a terminal and check out your git install:

$ git help log
$ git --version
$ git
Now back to the code - I tarred up my existing project (originally in svn):
$ tar cvfz project.tar.gz --exclude=.svn projectfolder/
Remove the directory:
$ rm -rf projectfolder/
Untar the project again, cd into the folder, and run init:
$ tar xzf project.tar.gz
$ cd projectfolder/
$ git init
Add the project to a git repository:
$ git add .
And commit:
$ git commit
The git commit process reminds me of cvs - assuming you're in the terminal and using vi, you'll have to open the file, insert your comment, then close and save in order to complete the commit.

Check the status of your repo (similar to svn's 'svn info'):
$ git log

One other thing to note: If you're using github, you'll be creating a local config file that sets up your connection to the github repository. You'll be able to check out, but you may need to add an extra line to allow you to push code back up to github (for more details, check here):
$ vi .git/config
In the "remote" section, make sure you have that last line:
[remote "github"]
url = git@github.com:git_username/projectname.git
fetch =  +refs/heads/*:refs/remotes/origin/*
push = refs/heads/master:refs/heads/master