GitHub and Xcode

Setting up a GitHub remote repository in Xcode...

First you need to make sure that you've got a local copy of Git up and running on your computer (Git is automatically installed with Xcode).

On Mac OS X 10.8.2 with Xcode 4.5.2 installed I get the following.

[ 1 Feb 2013: Updated Xcode to 4.6 - same Git version ]

If it's the first time you're using Git you need to set it up first.
1. Set your username and email address

To establish a secure connection between your computer and GitHub you need to generate an SSH key and then add the public key to your GitHub account.
2. Check for existing SSH keys on your computer

If you don't have a .ssh folder under your home folder and get a "No such file or directory" you don't have any local SSH keys - skip to step 4.

If you want to use your existing keypair skip to step 5.
3. Backup you're existing SSH keys and then remove it
4. Generate an SSH key on your local computer

Even though you don't have to provide a passphrase you need to do so.
Anyone who gains access to your SSH keys without a passphrase gain access to every system you use that key with!

(A passphrase is similar to a password in usage, but is generally longer for added security.)

Don't worry about having to enter a long passphrase every time you use the key.
SSH Agent is automatically started with Mac OS X and allows you to store your passphrase in your Keychain.
5. Add your public SSH key to GitHub

Copy your public SSH key to your clipboard.

Go to your GitHub Account Settings and then SSH Keys.

On the SSH Keys page click Add SSH key and paste your key into the Key field.

Click Add key and confirm by entering your GitHub password.

The new SSH public key will be added to your GitHub account (you will also get an email notifying you about the new key being added).
6. Test SSH connection to GitHub

When asked for a password, enter the passphrase provided above when creating your SSH keys.

Look for the "You've successfully authenticated" message shown above, indicating that you've successfully set up your SSH key.
7. Add GitHub as remote repository to a new Xcode project

Make sure you activate source control when creating your Xcode project.

In Xcode go to File / Source Control / Repositories.
Select your project and then Remotes and click on Add Remote.

Create a new GitHub repository.
Get the Location from the newly created GitHub repo (below) and enter into Xcode remote repository setup (above).

Now, when you're at a point where you want to save (push) your code to GitHub you first have to
a) Save your code to your local file system,
b) Commit (File / Source Control / Commit) to your local Git repository and then finally
c) Push (File / Source Control / Push) your commits to GitHub

(first time you push your code to GitHub Xcode will do a create as shown below).
View the GitHub commits for the project to confirm that your Xcode push was successful.