Putting Your Xcode Project on GitHub, Bitbucket, or GitLab

GitHub, Bitbucket, and GitLab simplify working on projects with other people. These sites also provide online backup for your projects in case your computer is damaged or stolen. Starting with Xcode 10 (Xcode 9 for GitHub) you can put your Xcode projects on GitHub, BitBucket, or GitLab without leaving Xcode. This article shows you how.

Prerequisites

You must have an account on GitHub, Bitbucket, or GitLab. Xcode can’t create an online account for you. If you don’t have an account, go to the site you want to use and create an account. GitHub is the most popular place to host projects online, but Bitbucket and GitLab let you have private repositories for free.

Your Xcode project must be under version control. The easiest way to place your project under version control is to select the checkbox to create a git repository when you create the project.

CreateGitRepoNewProject

If you have an existing Xcode project that is not under version control, choose Source Control > Create Git Repositories in Xcode to create a git repository for the project.

Adding Your Account to Xcode

Adding your GitHub, Bitbucket, or GitLab account to Xcode isn’t mandatory, but doing so makes things a little easier when you put your project online. Open Xcode’s Account preferences by choosing Xcode > Preferences and clicking the Accounts button in the preference window’s toolbar.

Xcode10AccountsPreferencesHighlighted

Click the Add button to add an account.

Xcode10AddBitbucketAccount

Choose GitHub to add a GitHub account, Bitbucket Cloud to add a Bitbucket account, and GitLab.com to add a GitLab account. Xcode will ask you for your username and password.

Putting the Project Online

You’re going to use Xcode’s Source Control navigator to put the project online. Open the Source Control navigator by choosing View > Navigators > Show Source Control Navigator.

SourceControlNavigatorAtStart

Creating a remote branch is how you put your project online. Select the Remotes folder, control-click, and choose Create Remote. A sheet like the following will open:

Xcode10AddBitbucketRepoHighlighted

Choose your account from the Account menu. If you did not add your account to Xcode, choose Add an account to add your account. Choosing an account will set the Owner menu to the username for your account.

Xcode sets the repository name to the name of the project for you, but you can change it if you want. If you would like to enter a more detailed description of the project, use the Description text view.

Choose the visibility for your project online: private or public. If you’re using GitHub, you won’t be able to create a private repository unless you have a paid plan on GitHub.

The remote name is initially set to origin. If you want a different name, enter it in the text field. The most common reason to change the name is hosting your project on multiple sites. Suppose you want to host your project on both GitHub and Bitbucket. To avoid confusion it would make sense to name the GitHub remote github and the Bitbucket remote bitbucket.

Click the Create button to create the remote branch and place your Xcode project online.

Where to Go from Here?

Now that your Xcode project is online, you’ll have the option to push your changes online every time you commit.

If you want other people to work on your project with you, they can clone your project by choosing Source Control > Clone in Xcode.