Geeks With Blogs
Code Without Fear Ruminations by Don Huff


Distributed version control systems (VCS’s), like Git, provide a rich set of features for managing source code.  Many development tools, including XCode, provide built-in support for various VCS’s.  These tools provide simple configuration with limited customization to get you up and running quickly while still providing the safety net of basic version control.

I hate losing (and re-doing) work.  I have OCD when it comes to saving and versioning source code.  Save early, save often, and commit to the VCS often.  I also hate merging code.  Smaller and more frequent commits enable me to minimize merge time and effort as well.

The work flow I prefer even for personal exploratory projects is:

  1. Make small local changes to the codebase to create an incrementally improved (and working) system.
  2. Commit these changes to the local repository.  Local repositories are quick to access, function even while offline, and provides the confidence to continue making bold changes to the system.  After all, I can easily recover to a recent working state.
  3. Repeat 1 & 2 until the codebase contains “significant” functionality and I have connectivity to the remote repository.
  4. Push the accumulated changes to the remote repository.  The smaller the change set, the less likely extensive merging will be required.  Smaller is better, IMHO.

The remote repository typically has a greater degree of fault tolerance and active management dedicated to it.  This can be as simple as a network share that is backed up nightly or as complex as dedicated hardware with specialized server-side processing and significant administrative monitoring.

XCode’s out-of-the-box Git integration enables steps 1 and 2 above.  Time Machine backups of the local repository add an additional degree of fault tolerance, but do not support collaboration or take advantage of managed infrastructure such as on-premises or cloud-based storage.

Creating a Remote Repository

These are the steps I use to enable the full workflow identified above.  For simplicity the “remote” repository is created on the local file system.  This location could easily be on a mounted network volume.

Create a Test Project

My project is called HelloGit and is located at /Users/Don/Dev/HelloGit.  Be sure to commit all outstanding changes.  XCode always leaves a single changed file for me after the project is created and the initial commit is submitted.

Clone the Local Repository

We want to clone the XCode-created Git repository to the location where the remote repository will reside.  In this case it will be /Users/Don/Dev/RemoteHelloGit.

  1. Open the Terminal application.
  2. Clone the local repository to the remote repository location: git clone /Users/Don/Dev/HelloGit /Users/Don/Dev/RemoteHelloGit

Convert the Remote Repository to a Bare Repository

The remote repository only needs to contain the Git database.  It does not need a checked out branch or local files.

  1. Go to the remote repository folder: cd /Users/Don/Dev/RemoteHelloGit
  2. Indicate the repository is “bare”: git config --bool core.bare true
  3. Remove files, leaving the .git folder: rm -R *
  4. Remove the “origin” remote: git remote rm origin

Configure the Local Repository

The local repository should reference the remote repository.  The remote name “origin” is used by convention to indicate the originating repository.  This is set automatically when a repository is cloned.  We will use the “origin” name here to reflect that relationship.

  1. Go to the local repository folder: cd /Users/Don/Dev/HelloGit
  2. Add the remote: git remote add origin /Users/Don/Dev/RemoteHelloGit

Test Connectivity

Any changes made to the local Git repository can be pushed to the remote repository subject to the merging rules Git enforces.

  1. Create a new local file: date > date.txt /li>
  2. Add the new file to the local index: git add date.txt
  3. Commit the change to the local repository: git commit -m "New file: date.txt"
  4. Push the change to the remote repository: git push origin master

Now you can save, commit, and push/pull to your OCD hearts’ content!

Code without fear!


Posted on Tuesday, June 19, 2012 5:00 AM XCode , Git , Process | Back to top

Comments on this post: Create a Remote Git Repository from an Existing XCode Repository

# re: Create a Remote Git Repository from an Existing XCode Repository
Requesting Gravatar...
Great guide, thank you. I just got a MBP for development on the road, and I wasn't sure how I was going to sync code. I put the remote repository on my home development machine, which I access from the road via Back To My Mac. After set up, I was pleased to discover that XCode can push/pull from the remote repository. No need to hit the commandline. Thanks again!
Left by Kevin Packard on May 15, 2013 8:36 AM

# re: Create a Remote Git Repository from an Existing XCode Repository
Requesting Gravatar...
thanks for the guide. finally got it working, but now when i go to another machine, open xCode and click check out existing project, it says "does not appear to be a git repository" any ideas?
Left by Dylan on Jan 18, 2014 6:23 PM

# re: Create a Remote Git Repository from an Existing XCode Repository
Requesting Gravatar...
@Dylan...I highly recommend SourceTree as a git client. I don't use built-in Xcode git integration. That said, it may not be an Xcode issue, but a problem with the remote repo. I would try the git command line tools to create a clone to figure out what's going on.

Good luck! -Don
Left by Don Huff on Jan 21, 2014 6:19 PM

Your comment:
 (will show your gravatar)

Copyright © codeWithoutFear | Powered by: