Setup iOS XCode & Github Integration
How to setup XCode and Github integration for a more organized iOS development using Objective C and XCode.
Whenever I start a side project that I am okay with putting up in the public domain, I use Github to manage the version control. For all my other commercial or not-meant-for-public-release projects are hosted using Bitbucket or a private Git repository on my own server.
Recently I started working on an iOS application for Rocreport (which happens to be an application for reporting civic issues around your area) and I thought it would be a great thing to make the source code available publicly. So, I decided to put up the source code on github.
However when I was trying to use the version control feature of Xcode and keyed in the details is of my github account, things would not just work as I had expected them to work. So I decided to chuck it and use the command line to setup the github repository for Xcode.
The good thing about this is you just need to use the command line only once when you start the project and after that you can use the version control feature of XCode to commit to your code into the repository. You can also do this if you already have an existing project and have decided to put it on github.
The first step in this tutorial is to set up your GitHub
Step 1: Create a repository on GitHub, or if you already have one you can simply use its URL.
Step 2: Get the SSH URL for your repository such as: [email protected]:ACCOUNT/PROJECT.git. you will use this in order to clone the repository later in this tutorial.
Step 3: This step is not a mandatory one but then if you do it you'll be relieved of not having to enter the github password over and over again whenever you do a commit or push / pull your changes. Generate your Public SSH key and add it to your GitHub Account
XCode Setup - this step sets you up for committing your XCode changes into the repository
Step 1: if you already have not created a project go ahead and create a new project in XCode. In the project creation menu you might see an option for local repository or source control integration, please do not select this as we will do it manually. After you are done, kindly close Xcode.
However if you already have an existing iOS project which you were planning to put up into your source control, then you can skip this step and go to the next step.
This is the third and the last step in this tutorial and it's about your local GIT Setup.
Step 1: Open up the console or the terminal and Browse to the project path where the .xcodeproj file is.
Step 2: Now all you need to do is execute the following from your command line (terminal / console), in the exact order as mentioned below:
git init git add . git commit -m 'Initial commit from local git' git remote add origin [email protected]:ACCOUNT/PROJECT.git git pull origin master
Once you do the above commands you will notice that the vim editor open, add the editor prompt do the following:
Hit 'i' to add a comment, for example 'Initial merge to sync local git with remote git'.
At this point you will notice that the VIM editor has closed.
Now all you need to do is enter the following command and the terminal:
git push origin master
At this point you should be all set and you can open the project on Xcode. If you did everything in the exact order that I mentioned above and did not come in a mistake then you should see that Github has been successfully configured in your XCode