Adding existing Xcode project to remote git Repo

I decided to post this as I found it a little frustrating finding good documentation on this anywhere. It seems that it was in bits pieces, so I’m posting it here, so I don’t have to go through the trouble anymore. Hopefully, others will find it useful as well.

There are two things you’ll need to do:

  1. Create the remote git repo
  2. Create the local git repo

Once you’ve done these, you should be able to commit and push those commits to your remote repo through Xcode. You won’t need to create the local repo, if you already have one for your project.

If you’re migrating a project from Subversion, you should export the project from the Subversion repo before starting. That will checkout your project, without the hidden .svn administrative directories. As git adds it own administrative directories, I imagine Xcode might get confused if both were there.

I use ssh to connect to the command line on the server where my git repos reside. You may need to adjust these commands for your environment.

On the remote server, change to the directory where you keep your git repos and execute these commands:

  1. mkdir Project
  2. cd Project/
  3. git init –bare shared=users

The –shared parameter is required if you need others to use the repo. The group, ‘users’ should be whatever group has access to the git repo. On my system, the git directory is owned by “me” with the group, ‘users’ having ‘rwx’ privileges (rwx-rwx-rx).

On your local computer, close Xcode and open up the Terminal app and change to your project’s directory and type these commands:

  1. git init
  2. git add *
  3. git commit -m “First commit”

Now launch your project in Xcode and go to the Organizer and click the Repositories tab. You should see your project under its repo name in the left pane.
Screen Shot 2013-01-10 at 11.44.21 AM

Click on the ‘Remotes’ folder under the repo name and then click the ‘Add Remote’ button at the bottom of the right pane. In the dialog box, type in a name for ‘Remote Name’ and then fill out the ‘Location’.

Screen Shot 2013-01-10 at 12.17.11 PM

The ‘Remote Name’ is arbitrary but, ‘Location’ should take the form of:
username@server_name:/path/to/repo. Click ‘Create’. If your info was correct, the dialog should disappear and you should be ready to push your commits to the server. When you go to push your commit, you should see something like this:
Screen Shot 2013-01-10 at 2.16.35 PM

Just click the ‘Push’ button and your changes will go to the server.

When working with a remote git server, you have to both, commit and then push, in that order. Commit only commits to the local repo. Push pushes the commits to the server. You’ll find both these commands under File->Source Control. Make some minor edits in your source and then try that now. You should be good.

A couple of tips:
Xcode gives you a key binding for ‘Commit’ (cmd-option-c), but not for ‘Push’. I edited my key bindings under Preferences and added cmd-option-p for ‘Push’. You can search for the ‘Push’ command in the key bindings search window and add one, if you like.

You can also commit your changes in the Organizer window, but, Xcode does not push these changes, so you’ll still need to push.

That’s it. Now I don’t have to worry about forgetting this.

EDIT: If you want to push to the remote server from the command line, you’ll first need to tell git the location of the remote repo. Use this command (ssh):
git remote add origin ssh://username@server/path/to/repo

Now, you can push your changes with this:
git push origin master

Where ‘master’ is the branch where you want your commits. I’m still learning git, but I believe git uses ‘master’, in the same way that subversion and cvs use the term, ‘trunk’.

missing source managed object model

I’ve been working through the Marcus Zarra book “Core Data” and although it seems quite good, I’ve found a few things that could have been made a bit clearer. As with most any book, there are errors, you can find the errata for the Core Data book here: Core Data errata . But some things are not as clear as they could be for total novices to CD. ¬†As you follow the book through and build the sample projects (available here: Core Data source), you might find things don’t work as the book indicates they should.

I’m going to assume you can figure out the Cocoa related issues, but the CD issues may not be as straightforward. In particular, when running the second version of the second project, you may get the error: “missing source managed object model”. I only found a couple of references to this error when googling, but because there were so few, and I double and triple checked my code against the book, I assumed the problem must be me. As usual, it was. The simple answer is this: Don’t give your project the exact same name as Zarra does in his book, if you want to also run the projects included in the book’s source code. There is a hash generated when a Core Data project is run and it’s stored in the xml file in the Application Support folder. This hash is used when running a CD project and when migrating a CD data store to a new version. If you run Zarra’s code and the project has the same name, the hash will get changed. If you then attempt the second version of the project with this changed hash, you’ll get the title of this post as an error. If you do get the error, delete the xml file, run the first version of the project and recreate the data. Now you should be able to run the second version of the project and your data will be migrated as expected. I’m sure there are more details that I’m not aware of yet, but this should get you passed this error. I’ll continue to post as I work through the book, so feel free to check in from time to time.