I’m just getting started on using XCode as an IDE and today I tackled getting my sample code into my subversion repository up on ProjectLocker. Using the Source Code Management features of XCode isn’t too bad, but there are quite a few steps and some of them are rather non-intuitive.
Set Up The Repository
The first thing you’ll need to do is set up a repository (or multiple ones if you want). I decided to create a unique repository for my iPhone development. Use the XCode Preferences and go to the SCM tab. Use the + icon as shown in the image and give this path a name. Then enter all the relevant information for your repository and click OK.
Use A Custom Build Location
Odds are good you don’t want all the temporary files in your build directory added to your repository so you need to get your build directory outside of your project directory. I did this by creating a shadow hierarchy. Let's say I have a path ~/Learning/ that contains several projects. I add a new directory /Learning/BuildDirectories and put a directory inside that for every project. Then do a Get Info on the project of interest and on the General tab use the Custom Location to relocate your build directory as shown in the image. Once that is done close the project but leave XCode Open.
Then use the Configure Roots & SCM button as shown with the orange arrow to set the repository to be used by this project.
In the resulting dialog, use the small popup selector to set the desired Root repository for this project as shown in the image at the left.
Import the Project
With the project closed (advice from the Apple manual) you can now import the project. Use the SCM menu and choose the first item Repositories. Click on the repository you created in the first step. I wanted a new directory for all my sample projects so I used the Create Directory (orange arrow in the image) to create a Learning folder. Don’t create folders for you project name, the import will do that for you. With the Learning folder selected use the Import Icon (green arrow in image) and navigate to the root folder of your project. When you are done you should see a folder for the root project and clicking on that will show all the files for the project. If you don’t see your files, first try clicking the reload button (purple arrow). Alternately, if you have the project open in XCode you can just drag the topmost item in the Groups &Files area directly over to the Repositories window. Drag it onto the folder you want to be the parent folder for your project.
Check Out the Project
Now you need to check the project out using the Checkout icon (blue arrow in the image above). I’m always a little paranoid about overwriting existing files (especially files that aren’t backed up to subversion yet) so I checked out the project to a new folder. I just used the same name and added an _SCM suffix so I could easily remember the old from the new. Once I’m convinced all is well, I’ll delete the original folder that wasn’t under version control. (Subsequently, I tried multiple methods of NOT replacing the original folder but I never found a method that worked. So now immediately after I create a new project I go through this process and delete the original project (which only has auto created files in it). If you want, after you delete the original folder you can remove the “_scm” suffix from your new folder. If someone else has the steps for importing in place in XCode so that you can skip this step I would love to hear how you did it.
Check In The Project
Now open the project you just checked out. Use the SCM->Commit Entire Project… menu item and do your first commit. I’m not sure this is necessary but it’s something recommended in other platforms I’ve used so I always do it. Now everything is set, and you can use all the features of your SCM from within XCode.