Xcode11 provides a set of tools that can optimize your GitHub flow. Let us go over some of the ways we can use GitHub with Xcode.
Setting up a new repo with Xcode is extremely easy. Although I love working on iTerm2, with my ZSH configuration, Xcode has tools that allow us to stay in Xcode!
Before we start, we have to take some initial steps to make sure Github has been configured properly on our Mac (If you’re using Xcode, I assume you’re on a Mac ). So before we start we will need to do three things. First, we will need to open up a terminal. Second, we will have to configure the “.gitconfig” file in our Home directory. Third, we will have to sign in to our Github account from Xcode! Let’s get started!
First, let’s start by opening the terminal. Click on “command + space” to bring out the spotlight search, write “terminal” and press enter. The terminal will show up!
Second, inside the terminal, let’s start setting up our Github user name and email. Use the “git config” command to check and set your credentials. Note that this email address will be associated with your commits.
$ git config --global user.name "Mona Lisa"$ git config --global user.email "firstname.lastname@example.org"
Third, we need to log in to our Github account from Xcode. So let’s open Xcode using Spotlight Search. Ones you’re in the Xcode, press “command + , ”. Now you should see the Preference window. Navigate to “Accounts”, and lets login to our Github account from Xcode by pressing the “+” icon on the bottom left corner. After selecting Github and pressing confirm, you will be able to add your Github user name and password.
Create a repository on Github with Xcode 😀
Like I said before, you don’t have to leave Xcode! First, we will create a Github repository straight from Xcode! This is my preferred method! Second, we will learn how to add a remote to your Xcode Project after making the repository on Github.
When you create an Xcode project for the first time you can create Git Repository on your mac. But this step can also be done after creating your project by navigating to your bar items and going to “Source Control” then clicking on “Create Git Repositories…”. You can see that from here we can also commit, push, pull, and discard all changes.
Now we can hit “command + 2”, which will show you the Source Control Navigator. Open the folder structure and you will find a handful of folders. The one we are looking for is Remotes. Control + Click on the folder and click on Create “<Your Project>” Remote…
A new window will show up, allowing you to enter a repository name and a description and allowing you to create the repository public or private. After pressing create, you can open up Github.com and you will be able to find the newly created repository under Repositories.
Add an existing remote 🖲
This can also be accomplished after creating the Github repository. All that you would need to is grab the existing remote.
In Source Control navigator, control + click on Remotes, click on Add Existing Remote. A window will show up allowing you to add the Remote Name and Location. You can leave Remote Name as origin, but Location must be set to your git remote. Make sure that your Location has a .git at the end!
Now if you click on the Clone or download button you will be able to find the project with an “Open in Xcode” Button 😎!
Branching with Xcode 🙀
We can create branches from inside the Source Control Navigator.
You can always navigate here by pressing “command + 2”. First, control + click the branch you want to branch from. Now you will be presented with a window that will allow you to name that branch. The new branch will show up in the folder called Branches.
You can easily Checkout from the branch by Control + Clicking on the brach and pressing on Checkout. This will now leave you on the selected branch.
Committing to Github with Xcode ✍️
The shortcut to commit in Xcode is “option + command + c”. This will bring up the window you see below.
This powerful tool for documenting your commits will show three main things. First, you can see all the changed files on the Navigator. Here you can pick what files you want committed. Second, you can see the exact changes made to that file. Third, on the bottom left corner, you have an option, Push to remote, which will allow you to push the changes to a specific branch.
I had a lot of fun writing this article! Find me on twitter if you have any comments or concerns, here.