Using GitHub with Xcode 6

Ben Tranter
Feb 3, 2015 · 4 min read

Today I tried to use Xcode 6’s built-in git support to push to my remote repository on GitHub, and couldn’t figure it out. I also couldn’t find anything for Xcode 6 and GitHub when I tried googling it, and only managed to find stuff for Xcode 5. After an hour or so, I finally managed to get it working, and it’s actually pretty slick. If you’re like me and have been struggling to get your project setup, then follow this quick guide. I’ll run through it from scratch.

Make A New Xcode Project

Open Xcode, start a new project, and then pick a template. For simplicity, I’m just going to make a Single View Application. When you’re prompted to choose a place to save your new project, make sure to check “Create git repository on”, followed by your choice. It’s probably going to be something like “My Mac”:

When you hit create, Xcode will automatically perform an initial commit for you. Let’s modify our ViewController to print a message, just so we have a change to commit ourselves:

Want this colour scheme? Get it here.

As you can tell, all we did was add a println. Now let’s commit our changes. In the top menu, click ‘Source Control”, then click “Commit”. It’ll bring up this crazy interface that allows you to see some sort of incredibly over-the-top fancy diff, and enter a commit mesage. Add your commit message and click “Commit 1 File” in the bottom right once you’re done. Time to go to GitHub.

Go To GitHub

Click the dropdown next to your account name, and click “New Repository”. Give it whatever name you like (it doesn’t have to be the same as your Xcode project name). Do not initialize your repository with a README. Just click “Create Repository” and you’re good to go:

Once you’ve clicked, you’ll see this:

Copy that link, and go back to Xcode.

Xcode Again

Once in Xcode, click “Source Control” again from the top menu. This time, select your branch name, and click “Configure”. Now, click “Remotes”. It’ll look like this:

Click the little plus sign in the bottom left corner and select “Add remote…” Enter the name you gave it on GitHub, and then copy and paste the URL of your newly created repo:

Click “Add Remote” and then click “Done” to leave that menu. From here, click “Source Control” from the top menu again, and click “Push”. It’ll ask you for your credentials, and it’ll work differently depending on whether you’ve enabled two factor authentication on GitHub or not.

Two Factor Auth Isn’t Enabled

Just enter your username and password. Congrats! You’re done.

Two Factor Auth Is Enabled

Every time you want to allow a new service to talk to GitHub, you need to create a new OAuth token. To do that, go back to GitHub, click the little “Settings” cog in the top right of the page, and select “Applications” from the left side menu:

You’ll need to generate a new access token. Click “Generate new token”, and enter your password to confirm. You’ll be presented with a bunch of options for the level of access that token has. For Xcode, the default options are fine. Enter a title for your new token and click “Generate token”. Once you do this, you’ll presented with a token. That is the only time you’ll see that token, so copy it to your clipboard right away. Once you’ve done that, you can return to Xcode.

Once in Xcode, select “Xcode” from the leftmost top menu, then select “Preferences”. Once that is open, click the “Accounts” tab. You’ll something like this:

Enter your GitHub username, and enter your newly generated token in the password field (not your GitHub password). Hit enter once you’re done to submit. Now, close the preferences pane, click “Source Control” again, click “Push…”, and congrats! You’re done. You can now push any new repos without having to go through to token generation process again.

That’s all you have to do to set up GitHub with Xcode. I hope you found this useful. If you’ve still got some free time on your hands, check out my blog at bentranter.io. Thanks for reading!

    Ben Tranter

    Written by

    Thoughts about programming & random stories.