Using branches and git with Xcode 4.1

It took me lots of time and many emails to a friend to fully understand how to do git branching from the command line.  I love the command line as I’ve been using UNIX for 20+ years now.  However, when I’m working in an integrated development environment like Xcode, it irks me to have to drop out to Terminal to handle revision control.  I finally worked out the steps to branching/merging within Xcode, and thought others might benefit from the steps as well.

First off, bring up the organizer’s repositories view and find your project on the left hand side.  Click on the yellowish folder labeled Branches inside of it and then at the bottom of the window click on the Add Branch graphic.  Give the branch a name in the dialog that appears, and be sure to select the checkbox at the bottom to Automatically switch to this branch.

Back in the organizer, if you click on the blue folder representing your cloned project you’ll notice in the upper right part of the window Xcode will tell you that you’re now on your newly created branch.

At this point go back into Xcode’s editor and make all of your changes.  Once you’re done, and you’re ready to push this branch up to the server, go to File->Source Control->Push and choose the branch name you just created.  If this is your first push to the new branch, Xcode will create it for you at this point.

This is where it got tricky, at least for me.  You can’t do your merge operation now.  Git wants you to be in the branch you’re merging to, not the branch you’re merging from.  To accomplish this go back into the organizer’s repository view and click on your blue folder again.  At the bottom of the window you can select Switch Branch to go back to your master branch (or whichever you want to merge these changes into).  Now go to File->Source Control->Merge and read the bold text at the top of the window.  The key word in the displayed sentence is current.  So, choose the branch where you just made your changes, and those will be pulled into the master branch.

Once you’re satisfied with the merged changes, just commit and push this back up to the master.

4 thoughts on “Using branches and git with Xcode 4.1

  1. Thanks, this cleared it up a bit for me. Apple’s docs are incomplete and I want to know what it does ‘under the hood’.

  2. Very nice. I have a question on branching I want to create a branch for the next version of iOS. I’ll likely make changes to the master branch that would be released on the current version of iOS. I want to keep the master branch pure for the current level of OS. So what I want to be able to do is to merge the update in the master to the updated OS version. Will there be a problem with merging the master with changes back into the branch that was related fro. It.



Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>