At WWDC 2017’s talk of GitHub and the New Source Control Workflows in Xcode 9, new tools were announced for exploring the source control history of our projects, GitHub’s integration with Xcode and how we can use the source control navigator to commit changes, pull & push the code to GitHub, see the entire commit history and information — all integrated right inside the Xcode. Sounds good?
Let’s dive right with these five easy steps to explore how we can get the full advantage of GitHub within Xcode. If you do not have Xcode 9, download it here.
1. Add a GitHub account
Open Xcode -> Preferences -> Accounts and add an account by clicking the plus sign at the bottom. Now, click on the GitHub option and enter your GitHub’s email and password.
Congratulations, your GitHub account is added to your Xcode’s Source Control Accounts.
2. Clone the repository
Open Xcode, from the menu, select Source Control -> Clone. A new window will appear that will list all the projects in your repository including the one you have starred. Select a project and click Done.
3. Source control navigator
After you have cloned the project, select your project and press Command+2 to open the brand new Source Control Navigator. You can see the entire commit history of the project. Select a commit and open Inspector. It will display the branches which have your commit, the commit hash, date, author and the commit message. The best part — we can even filter our commits in the source editor on the basis of author, commit message, branch, etc.
4. Basic GitHub operations (commit, push, pull & create a branch)
Create a new branch by right-clicking the master branch from the navigator area -> New Branch from “master” and a new branch will be created. Commit the changes by selecting from the menu Source Control -> Commit.
You will see a window is displayed. Add the “commit message” at the bottom and make sure the “Push to remote” button is checked at the bottom.
In order to view the branch on GitHub, right-click on the newly created branch -> View on GitHub. You can see your branch automatically created on the GitHub.
Tag a commit by right-clicking it -> Tag. Name the tag (like v1.0) and add a message.
You will see the commit gets tagged with that version.
You can try other operations like merging a branching, deleting a branch, discarding all the changes (like a git stash), checking the commits made for each file etc.
This is completely a new feature that has been integrated by Apple in Xcode. Think about the time that will be saved which is otherwise consumed in writing the git related operations in your terminal.