3 min read

Connect GitHub Repository with Xcode

Connect GitHub Repository with Xcode

If you’ve been following along with our Times Up app in the Getting Started with iOS and Xcode article, we now have a project that we know builds and runs, has a .gitignore file indicating which of our project files we don’t want under source control, and has been placed under source control with an initial commit. Next, to connect our Xcode project with a GitHub repository, we’re going to keep things simple by setting our GitHub credentials on our machine and then creating our GitHub repository directly from Xcode.

Requirements:

  • An Xcode project already under source control
  • Xcode 11 is used for this setup

Configure GitHub on your Mac

The first step is to configure our “.gitconfig” file in our home directory. Open the terminal and from our home directory we’re going to use the “git config” command to set our GitHub credentials:

$ git config --global user.name “Isaac Newton”
$ git config --global user.email “example@email.com”

Logging into GitHub from Xcode

The next step is to log into our GitHub account from Xcode. Open the project in Xcode and go to the Preferences window by hitting command + , from your keyboard. Next, we’ll want to navigate to Accounts and login to GitHub by pressing the “+” icon in the bottom left corner. Select “GitHub” as the type of account we want to add and then click continue.

GitHub account in Xcode

Now we want to sign into our GitHub account. Enter the email linked to your GitHub account in the Account field. If you don’t already have an access token, you can follow the “Create a personal access token” link in the sign in window and create one.

Sign into GitHub in Xcode

Now that we’ve connected our GitHub account in Xcode, we can set a description for that account. I’m setting mine as “RisingDevHabits”. For the purpose of this setup, we’ll also be leaving the Clone Using setting to HTTPS.

Creating a Github Repository Using Xcode

So far, we’ve set up our GitHub credentials on our Mac and signed into our GitHub account via Xcode. The last step is to create our GitHub repository directly within Xcode. There are other ways of creating a repository and linking it with our project, but in this example we’re going to stick with Xcode.

If you haven’t been following along with the Getting Started with iOS and Xcode article and/or your project isn’t already under source control, you can follow the instructions under Step 5: Placing the Project Under Source Control in this article.

To create our remote repository, open the Source Control Navigator by hitting command + 2 and right click on the Remotes folder.

Click on Create “<Your Project>” Remote. If you have been following along with the Getting Started with iOS and Xcode article, you should see Create “Times Up” Remote.

Create remote repository in Xcode

Choose a name for your repository and add an optional description. You can also decide whether you want it to be a public or private repository. This is what the example for the Times Up app looks like:

Setup remote repository in Xcode

After creating the repository, you can check your GitHub account and find the newly created repository under Repositories.