Using git with Xcode

Disclosure: Links to other sites may be affiliate links that generate us a small commission at no extra cost to you.

About git

Git is a distributed version control system that is easy to use and free.  I will describe the use of git with Xcode on Mac OS X for iPhone development.  Because git is distributed, each client has a full copy of the repository.  This results in great performance in most situations involving the management of source code files.

Installation

A disk image for Mac OS X is available here.  Simply download, open it, and run the .pkg to install.

Xcode Preparation

I’ll be using command line, even though GUI clients are available for Mac OS X.  Why?  Because command line is quick and easy, git isn’t so complicated as to require a GUI.

It’s generally considered poor practice to check build outputs and intermediate files into your source control system.  The binaries tend to bloat the underlying storage mechanisms and in addition, why store what you can re-create from source later?  It can also complicate the check in and merge process , as binaries would have to be manually resolved.  This may be an issue for a multi-developer team.

The easy way to do this in Xcode is to change the build output location. This can be found under “Project” -> “Edit Project Settings” in the application menu:

If you have already built previously, you may want to use “Build” -> “Clean All Targets” to remove any outputs in the old location.  I also like to use the rm command on the command line to remove the now empty (and unnecessary) directories.

First Commit

Now, to the command line.  You must change directories to the location of the project to commit, then create the initial repository using the init sub command.  Then add . (all files and directories underneath), then commit.  Text editor will appear , edit the commit message, save, and quit

[Mac-Book-Pro]$ pwd
/Users/tplatt/development/iphone/research/HelloWorld
[Mac-Book-Pro]$ git init
Initialized empty Git repository in /Users/tplatt/development/iphone/research/HelloWorld/.git/
[Mac-Book-Pro]$ git add .
[Mac-Book-Pro]$ git commit
[master (root-commit) 36395bc] Initial checkin, basic functionality.
16 files changed, 4510 insertions(+), 0 deletions(-)
create mode 100644 Classes/HelloWorldAppDelegate.h
create mode 100644 Classes/HelloWorldAppDelegate.m
(Other output removed for brevity)

Changing and updating

git diff  – to check for differences

git log – to see history

git add (filename) – to add new files

git commit -a – to commit changed files (and any added since last commit)

Sharing with others

Create a “magic file” in each .git repository that is OK to export:

touch git-daemon-export-ok

Then run the git daemon

git daemon &

The remote client can then use:

git clone git://(hostname)/Users/tplatt/development/iphone/research/HelloWorld/.git

Other commands

git user’s manual

About the author

Tim

I'm an all around computer junkie, interested in many aspects of programming, operating systems, and enterprise IT technologies. I love Mac OS X, Linux, and Windows and more!