Category: Version Control

What Xcode Files Should Git Track and Ignore?

When you start using version control in your Xcode projects, you may become confused about which files git should track and which files git should ignore. This confusion is normal. Xcode projects contain much more than your Swift files, and some of these extra files are basically unreadable. What files in your project should you tell git to ignore?

Fortunately the site gitignore.io has solved this problem for you. Go to gitignore.io, enter Xcode in the search field, and click the Create button. You will get a git ignore file with a list of file types that git should ignore. Add the git ignore file to your project folder.

Need More Information on Using Git with Xcode?

Check out my version control book. It has an entire chapter on ignoring files, including what to do when git starts tracking an unwanted file.

Cherry Picking a Git Commit in Xcode

Xcode 11 adds support for cherry picking commits. Cherry picking involves taking a commit from one git branch and applying it to another branch. Cherry picking lets you apply a commit to a branch without having to merge all your recent commits into that branch.

Take the following steps to cherry pick a commit in Xcode.

  1. Open the source control navigator by pressing Cmd–2.
  2. Checkout the destination branch, the branch that will receive the cherry picked commit.
  3. Select the branch with the commit to cherry pick. Xcode’s editor will show all the commits for that branch.
  4. Select the commit.
  5. Right-click and choose Cherry-Pick.
  6. An alert will open asking if you want to cherry pick. Click the Cherry-Pick button.

Want to Learn More About Version Control?

Check out my version control book. It shows you how to do the most common git tasks without leaving Xcode. Some of the material covered in the book includes seeing the changes you made to your code, branching, and going back to earlier versions of your project.

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 are also fine to use.

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 > New Git Repository 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.

UPDATE

GitHub requires you to create a personal access token and use that instead of a password for authentication.

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 or by pressing Cmd–2.

SourceControlNavigatorAtStart

Newer versions of Xcode have Changes and Repositories buttons at the top of the source control navigator. Click the Repositories button to show the branches in the git repository.

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. Xcode has problems with uppercase letters in Bitbucket repository names. Use all lowercase letters if you’re using Bitbucket. 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.

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.

Work on your Xcode project in a local branch. Push your changes to move them to the remote branch on GitHub, Bitbucket, or GitLab.

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

Want to Learn More About Version Control?

Check out my version control book. It shows you how to do the most common git tasks without leaving Xcode. Some of the material covered in the book includes cloning projects from GitHub, branching, and going back to earlier versions of your project.