If you have worked on an existing Xcode project for some time and decide that you want to add a Git repository to better track your files, you will want to do the following steps:
- Start off by backing up the folder as a general safety precaution
- Now would be a good time to add an ignore file. See ignore file section below.
- In a terminal, CD to your project directory containing your .xcodeproject file
- Run the commands (credit to Mcannon):
- git init
- git add .
- git commit -m “Initial Commit”
- Close and restart Xcode if you had it open.
- To verify, open your Xcode project and click Source Control from the top menu. You should now see Working Copies with your project name – Master below it.
Your project file has a bunch of user settings such as breakpoint locations that will by default be stored into the repository. This is not necessarily a bad thing however it can be frustrating to have this pile up the list of uncommitted code every time you check in. Also, in a multi-user environment, you’re likely better off avoiding all the user setups. In addition, files such as build files generally shouldn’t be added to Git, among others.
There is a very handy thread over at Stack Overflow where Adam created a template file to use for your ignore file. I recommend using the template file (it works with Xcode 4/5 at the time of this article regardless of its commenting for mostly 4) provided there. This file will reside in your root project directory (containing your .xcodeproject) where we will be making the repository. It’s file name must be .gitignore
If you have issues with the ignore file appearing to go unnoticed. You may have some files checked in prior having the rules set in place. Check out this post for tips on how to resolve that.