Introduction to Git: Version Control for you and me (on OS X 10.5 Leopard)

It looks like someone brewed up a snazzy installer for Git on Leopard. It's up here on Google Code.

Update: Aug. 5, 2008 – There’s a sick & amazing resource for Git that is beyond anything this post hopes to touch. For a better Intro to Git, go here.

While I’m relatively new to the field of version control, I’ve been through the basics of CVS and SVN, and at work, SVN is part of my programming workflow.

That said, people are hot for Git, and so I’m going to explore its installation on Leopard (OS X 10.5), and basic usage.

Get Git

First thing’s first, I picked up the latest Git package (1.5.5.1 at the time of this writing).

download and extract from here

or from your terminal, perform the following commands:

Build Git

Now that we’ve unpacked Git, we have to build it.

note: OSX 10.5 doesn't come with the libraries that are necessary for the build process. Before proceeding, you'll probably want to obtain Apple's Xcode package and install it. (download and install Xcode 3.0)


another note: You'll also want to have enabled your OSX root account (You can read how to do that here)

From your terminal, navigate to the directory where you extracted the files and execute the following commands:

Go to your home dir and confirm that git was installed OK by checking the version. If you see git version 1.* then you should be OK.

Using Git

Let’s set up a repository, add a project, add some files, remove some files, perform some commits, and look at the log. I’m totally using SVN lingo here, because I’m literally writing this post as I install and use Git.

Set up a repository

I’m going to create a directory called /test in my ~/Sites folder for this process. I don’t know how big a mess I’m going to make. I’m also going to touch a few files so I have something to version.

Now I’m going to create an empty repository inside of ~/Sites/test

Yay! It didn’t break!

Add files to my Git repo

Using git add we can tell Git to keep track of certain files for versioning. This will be important later when we commit changes to files we’ve added.

Still in /test let’s add these files and check the status.

Hotness. Now how about I change index.php, and we commit those changes.

Nice. Notice that I used -a in my command. This tells Git to look for changes in all the files that I told it to track with git add.

Removing files from Git

I don’t know about you, but I’m sick of styles.css lording up my repo. Time to remove it.

If we do a status before we commit this change, here’s what you should see:

Other basic Git commands

Here’s an excerpt from the Git Cheat sheet:

git diff
show a diff of the changes made since your last commit

git status
show files added to the index, files with changes, and untracked files

git log
show recent commits, most recent on top

git show
show the changeset (diff) of a commit specified by , which can be any
SHA1 commit ID, branch name, or tag

see more cheat-ey commands at http://cheat.errtheblog.com/s/git/

GIT package for TextMate

If you haven’t already, I’d recommend trying out TextMate as your text editor for coding on OS X. You can learn more about it here

In the event that TextMate is already your editor of choice, then let’s get started.

If you haven’t already, you’ll need to create a /Bundles directory in OS X’s /Application Support folder, and navigate to it.

Now we perform a git clone on the bundle repo and pull it down to our local /Bundle directory. Using the git clone command below, you should see similar output.

Now to make sure TextMate picks up on the new bundle, tell it to reload bundles.

Now you should have a Git item in your Bundles menu in TextMate.

More information can be found here: From TextMate’s site and here: From gitorious.org

Conclusion

Okay, I’ve learned a lot. You may have, too. I think I’m going to create a sequel to this post that covers remote repo creation & git push and git pull-ing files to a remote location.

Here are some of the resources I used to create this post, and other stuff I found along the way.

References & additional reading

Additional Notes

This post was inspired by my co-worker, Nick Sergeant’s posts about Drupal and CVS (From HTML mockup to a full Drupal site: a tutorial – Part II: Site Setup, Content and Modules., Drupal 6ers… register your theme functions! Here’s how., and Painless Drupal revision control with CVS and Subversion on a shared host.).

Also, most of the way through this post, I found this succinct set install commands from Justin Reagor here. I’ve adjusted the ./configure and make—prefix options based on his post (I wasn’t setting—prefix, which means git was installed in an incorrect location on my computer).

If you enjoyed this post, then tweet about it!