Source Control Integration

Xcode: The IDE Itself

Chapter 8 ยท Source Control Integration

Chapter 2 ended with a question: which of a project's files should go into version control? This chapter covers the tools Xcode gives you for working with Git, and which of them are still current. The sources are uneven. The most detailed walkthrough is a 2014 tutorial written for Xcode 5, and Apple's own documentation pages did not return usable text, so I checked what I could through an Apple Developer Forums thread and tutorial summaries and marked the rest. Git & GitHub Foundations covers Git itself, so this chapter stays with how Xcode presents it.

Xcode Speaks Git

Xcode has worked with Git since at least version 5. A tutorial from April 2014 says Xcode "since version 5" has enriched capability for working with Git, and that source control tasks live in the Source Control menu and the Accounts preferences. When you create a new project, one of the setup steps offers a checkbox to create a Git repository on your Mac. You can also initialize a repository yourself in Terminal with git init.

Mind the Date on Every Source Here
That tutorial is more than a decade old. Menu names, window layouts and even the commit workflow have changed since, as the staging change below shows. Use the descriptions as a map of what Xcode can do, and confirm the exact steps in your own version.

Committing, and a Real Change in Xcode 15

In the 2014 tutorial you choose Source Control → Commit, and a window lists the modified files with checkboxes and a side-by-side code comparison. You can commit selected changes or discard others from a context menu.

That changed. An Apple Developer Forums thread records that starting in Xcode 15 you must explicitly stage changes to include them in a commit, whereas previously changes were automatically staged when you committed. A DTS engineer in the thread pointed to the Xcode 15 release notes, and noted that staging is standard Git functionality documented in Git's own materials. So the commit window in a current Xcode has options for staging and appending that the 2014 window did not.

Staging in One Sentence
Staging means preparing specific changes to be included in your next commit, so each commit can contain exactly what you meant it to. That is ordinary Git behavior and Xcode now exposes it directly.

Looking at History

FeatureHow the sources describe it
HistorySource Control → History shows all commits with messages and the number of files modified
BlameView → Version Editor → Show Blame View splits the selected file into segments with the commit author and message, so you can see when code was committed and by whom
CompareThe Version Editor shows two panes for comparing versions, with differences highlighted; a button with a clock image lets you pick a previous commit

Branches, Merging and Conflicts

The 2014 tutorial describes creating a branch through the Source Control menu, switching between branches, and merging with "Merge From Branch" and "Merge Into Branch." During a merge, Xcode shows comparison windows with red or blue areas for replacements or additions, and toolbar buttons let you choose or reorder lines to resolve a conflict before finishing. It also describes a "Discard All Changes" option that reverts files to their last committed state after confirmation.

Discarding Is Permanent
Discarding changes returns files to the last committed state, so anything uncommitted in those files is lost. Commit or stash first if there is any chance you want it back. I have not tested how this behaves in a current Xcode.

Pushing to a Remote

One tutorial says that after committing you can choose Source Control → Push, select the origin (by default the main branch), and click Push to upload your changes to GitHub. The 2014 tutorial does not describe remote repositories at all. I could not confirm the current steps or how Xcode handles authentication to a hosting service, so use whatever your Xcode's Source Control menu offers and check Apple's release notes.

Xcode or the Terminal?

  1. For quick commits, viewing blame and comparing versions of a file, Xcode's built-in tools are convenient because you stay in the editor.
  2. For anything unusual, such as a difficult merge or history rewriting, Git in the Terminal follows Git's own documentation exactly, and the same repository works in both.
  3. What to commit is still a team decision. I did not verify Apple's or the community's recommended list of files to ignore for an Xcode project, so decide that with your team and check current guidance.
# Create a repository from Terminal in the project folder git init

Hands-On Exercises

Exercise 1

Explain what changed about committing in Xcode 15, and say why a tutorial written for Xcode 5 could mislead a beginner using a current version.

๐Ÿ“„ View solution
Exercise 2

You want to find out who last changed a particular line and what the commit message said. Say which Xcode feature you would use, where you find it, and what it shows.

๐Ÿ“„ View solution
Exercise 3

List three things about Xcode's source control this chapter could not verify, and say where you would check each.

๐Ÿ“„ View solution

Chapter 8 Quick Reference

  • Git in Xcode: since at least Xcode 5; Source Control menu; optional repository checkbox at project creation
  • Xcode 15 change: changes must be explicitly staged before committing (per an Apple Developer Forums thread pointing to the release notes)
  • History, blame, compare: Source Control → History; View → Version Editor → Show Blame View; two-pane comparison
  • Branches and merges: New Branch, Merge From/Into Branch, conflict comparison window (2014 tutorial)
  • Push: Source Control → Push (one tutorial; current steps unverified)
  • Unverified: the Source Control navigator's current layout, authentication, and which files to ignore