Thursday 15 December 2011

Setting up a project in XCode 4.2 with Git and Bitbucket

Xcode now includes a powerful source control client which supports (in fact by default uses) the Git DVCS.

Bitbucket have recently started offering unlimited private repositories (for free!) and now support both Git and Mercurial repositories.

If you're starting a new closed source iOS project and want to store your app source safely offsite but at the same time can't initally afford to pay a fee for the privilege then this is great news.

An hour or so ago, I discovered this great news myself and decided to give it a try. I've had some dealing with various source control systems over the years but up until today I've not had the pleasure of using Git. I've previously been a CVS and Subversion user.

I did a quick google to see if many people were using Bitbucket with Xcode and discovered quite a few threads where people had found issues getting the two to play nicely together, so I decided to have a go myself.

Its quite an easy process in Xcode 4.2, here are the steps:

Step 1: Register with Bitbucket

Step 2: Start a new Xcode project, select the option for Xcode to put your source under version control. It will create a Git repository for your project. You can find the repositories Xcode is managing in the Organizer on the Repositories page.

Step 3: Create a new repository on Bitbucket.  Select Git as the repo type.

Step 4: Bitbucket will show you a command to type to clone your repository locally. We won't use this command but copy the url from the command eg:

https://jumpsource@bitbucket.org/jumpsource/hellobucket.git

Step 5: In Xcode open up the Organizer and switch to Repositories, find your new project's repository. Under your repository name you'll see 3 folders: Branches, Remotes & YourProjectFolder, select Remotes.

Step 6: At the bottom of the screen you'll see the Add Remote option - select it and enter a name for your remote repository and in the URL paste the one you copied from bitbucket in step 4.

Step 7: Click Create, enter your username and password when prompted.

Step 8: You should now have an empty folder in the Remotes view with the name of your remote repository.

Step 9: You now need to Push your local changes to your empty remote repository. To do this, from the menu in Xcode choose: File -> Source Control -> Push. Select the remote repository to push to - if your reading this article there will probably just be one remote - the one you just configured in step 6 & 7. Press Push, Xcode will chug for a bit, then report (hopefully!) that the push was successful.

Step 10: Refresh your page at Bitbucket and you will see your updates.

3 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. So do I have to do step 9 every time I want to update Bitbucket or does it do it automatically?

    ReplyDelete
  3. Woohoo! You're awesome. Thank you for the tutorial.

    ReplyDelete