Setting up git for use with xcode projects

Filed in iOS Development | Comments (0) |

My goals

This past year, I have read many discussions about the pros and cons about distributed version control systems (DVCS), and git in particular. It seemed like it might be a better fit for the style of development I have been doing the last few years, but since our current process worked well enough, it wasn’t worth the bother to switch at the time.

But, I was intrigued, and decided to use git in a project sometime soon, and even though my new project is a solo project at the moment, it gives me to get accustomed to git.

I had some pretty fuzzy goals when starting:

  1. Use git for version control
  2. Integrate git with XCode as much as possible
  3. Setup separate physical machine for a remote repository

And at the time, I wasn’t quite ready to begin, so I gathered my thoughts into a simple project on Things. (Things deserves a post of it’s own — very useful, flexible, and straightforward.)

Setting up a new server

Fortunately, since I wanted a remote repository on physically separate machine, I had an old pc sitting around that had not yet been completely scavenged.

A friend of mine recommended Ubuntu, so I decided to try it. I retrieved the latest installation image, Ubuntu 8.10, burned it to cd, and installed. The installation went without a hitch on my 4+ year old machine, thanks Paul!

Setting up a remote git repository

Ubuntu does not install ssh or git by default, so I installed them both from a terminal window using apt-get.

$ sudo apt-get install ssh
$ sudo apt-get install git-core

I have used subversion for years, but am new to git, so I googled for some tips. The article ‘Remote Git Repos on Ubuntu: The Right Way‘ was very useful. I followed what Drew discussed and had no issues at all, and I was now two for two.

XCode and source control

XCode comes with in-built methods to deal with some source control systems, but nothing for git.

Git for the Cocoa Developer: A Typical Workflow describes how Christopher Roach setup his git project directory. Since I had followed Drew’s steps for configuring git, I really only needed to use the configuration information for ‘.gitignore’ and ‘.gitattributes’ described in the section ‘Config the repository for Cocoa development’.

I had an existing xcode project that I wanted to put into git, so I followed these steps:

$ cd myproj
$ git init
$ vi .gitignore

# Added these lines to .gitignore
# xcode noise
build/*
*.mode1v3

# osx noise
.DS_Store
profile

$ vi .gitattrbutes

# Added this line to .gitattributes
*.pbxproj -crlf -diff -merge

$ git add .
$ git commit -m "Initial load of myproj"
$ git remote add origin git@myserver:myproj
$ git push origin master
$ cd ..
$ rm -Rf myproj
$ git clone git@myserver:myproj myproj


I then reopened my project in xcode to make sure I did not break anything. (It was fine.) I’m sure I will be fiddling with ‘.gitignore’ as I move along, but for now I’m calling it good enough. Obviously, since xcode is unaware that I am doing version control, I will have to manage that via the command line or other tool. Since this is as much a learning project for me as anything, I’m okay with that for now — but I reserve the right to vent here later!