As an iOS developer spending most of my time in Xcode, I realized how unproductive I was due to constantly switching back and forth between Xcode, Terminal, Github, and Source Tree. As a result, I decided to dive into Xcode Git integration with Github. Let’s take a look at the Github integrated features and how they can help you become a better and more productive iOS developer.
Why should you leverage Xcode Git integration?
Once a project reaches a few hundred commits, 4–5 developers or six months of active development, it becomes increasingly more difficult to have context on the source code without navigating the Git history. You simply don’t know who wrote the code and why, who introduced the bug and when, or who fixed it. Even if it was you.
The classic approach taken by iOS developers in dealing with Git version control is usually a combination of multiple tools: Terminal for basic Git commands, a diff editor (such as Source Tree) to visualize code differences, Xcode to write & build code, and Github for more advanced git blame and revision history tasks. That’s crazy because you can do all this in Xcode.
What Git features does Xcode support?
Despite the fact that we, iOS engineers, like to complain a lot about it, Xcode is actually an extremely powerful IDE. From advanced debugging capabilities to the source control navigator introduced in Xcode 9, you can achieve most of the regular development tasks without ever leaving the Xcode app.
Source Control Basic Menu
Xcode’s Source Control gives you quick access to the most popular Git actions, which traditionally you’d run in the terminal or on a Git GUI client. Here are the most relevant features:
- Run basic git commands with just a couple of clicks — push, pull, commit, reset.
- Create and clone Git repositories.
- Visualize all the changes that are about to be committed, in a built-in diff editor
Source Control Navigator
Introduced in Xcode 9, the source control navigator is directly integrated with Github. Here are the most powerful features:
- Navigate your entire Github repository
- Browse Git branches
- View the logs (commit history) for each branch
- Visualize the detailed diffs for any commit, in a beautiful split pane editor.
To enable the source control navigator, you need to add your Github account in Xcode ->Preferences ->Accounts. To open it, you can simply press Cmd + 2.
Git Version Editor
By far, this is the most powerful feature of Xcode’s source control integrations. It’s extremely useful, especially in large iOS teams, and it blends in perfectly with the regular development flow, adding Git functionalities to the code editor itself.
Once you toggle it on, you can view the entire Git history of the currently open file instantly. Here’s what you can find out:
- Who add each line of code and in what commit
- What are all the commits that ever touched this file
- What are the currently uncommitted code changes affecting this file
Traditionally, mobile developers had to combine multiple tools to retrieve and track the historical context of the source code. Xcode Git integration allows you to seamlessly execute all the Git-related actions you can think of directly within the IDE. By leveraging Xcode’s advanced Github integration, you are reducing unnecessary friction, and therefore, increase your productivity significantly.