# How To Use Git Source Control with Xcode 9

**URL:** <https://forums.kodeco.com/t/how-to-use-git-source-control-with-xcode-9/33618>\
**Category:** 🎓 Courses & Articles\
**Created:** [August 23, 2017, 7:36pm UTC](https://forums.kodeco.com/t/how-to-use-git-source-control-with-xcode-9/33618 "2017-08-23T19:36:09Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![rcritz](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/rcritz/32/111201_2.png) [@rcritz](https://forums.kodeco.com/u/rcritz)\
**Post date:** [August 23, 2017, 7:36pm UTC](https://forums.kodeco.com/t/how-to-use-git-source-control-with-xcode-9/33618/1 "2017-08-23T19:36:09Z")

</div>

In this tutorial, you'll learn how to use git source control with Xcode 8; whether committing or reverting, branching or merging, this tutorial has you covered.

* * *
 This is a companion discussion topic for the original entry at [https://www.raywenderlich.com/675-how-to-use-git-source-control-with-xcode-9](https://www.raywenderlich.com/675-how-to-use-git-source-control-with-xcode-9)

---

<div class="post-metadata">

**Author:** ![musa](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/musa/32/81494_2.png) [@musa](https://forums.kodeco.com/u/musa)\
**Post date:** [September 8, 2017, 1:18am UTC](https://forums.kodeco.com/t/how-to-use-git-source-control-with-xcode-9/33618/2 "2017-09-08T01:18:01Z")

</div>

Hi,

I was just wondering is it possible to switch between git source control? So that if you’ve started git versioning within xcode but later decide to want to use the command line and then maybe even later revert back to xcode, is that possible?

---

<div class="post-metadata">

**Author:** ![rcritz](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/rcritz/32/111201_2.png) [@rcritz](https://forums.kodeco.com/u/rcritz)\
**Post date:** [September 8, 2017, 1:37am UTC](https://forums.kodeco.com/t/how-to-use-git-source-control-with-xcode-9/33618/3 "2017-09-08T01:37:03Z")

</div>

Absolutely! Git is git, and you can use the integrated capabilities in Xcode and the command at a terminal prompt together. That’s my normal way of working, in fact. I do some things in Xcode and some in the terminal window. There’s nothing special at all that you need to do.

---

<div class="post-metadata">

**Author:** ![slsdeveloper17](https://s3.amazonaws.com/cdn.raywenderlich.com/community/forum-assets/noun-game-ghost-878668.png) [@slsdeveloper17](https://forums.kodeco.com/u/slsdeveloper17)\
**Post date:** [September 22, 2017, 5:26pm UTC](https://forums.kodeco.com/t/how-to-use-git-source-control-with-xcode-9/33618/4 "2017-09-22T17:26:01Z")

</div>

Hi Richard,

First of all great article, and I have been successfully using git with Xcode and Bitbucket for the last few months, and I have recently published my app to the app store, and have begun working on version 1.1 of my app (version 1.0) is in the app store.

I have made significant changes since the release as it has been live fore a couple of weeks now. Today I have a customer calling with a problem with the 1.0 version they have from the app store. I feel sure if I still had the 1.0 version loaded on my machine, I could connect my test iPhone and debug the problem an find it in just a few minutes.

Here’s my question. How would I go about downloading a copy of the 1.0 version ( I can see it listed in my commits in both Xcode and on [Bitbucket.com](http://Bitbucket.com)). and being able to compile that and load on my test device with out losing or corrupting my current work on version 1.1.

It seems to me that this should be a pretty simple task. Is that true or am I asking way to much from git.

Thanks in advance you or anyone who comments can give, I surely will appreciated it.

---

<div class="post-metadata">

**Author:** ![rcritz](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/rcritz/32/111201_2.png) [@rcritz](https://forums.kodeco.com/u/rcritz)\
**Post date:** [September 22, 2017, 5:51pm UTC](https://forums.kodeco.com/t/how-to-use-git-source-control-with-xcode-9/33618/5 "2017-09-22T17:51:00Z")

</div>

Nope, you’re not asking too much at all; it’s easy to do.

If you’re looking at the commits in the **Source Control navigator** , find the commit that is your V1.0 release, **right-click** and select **Branch from “xxx”…**. That assumes you’re going to need to make changes to the V1.0 source code. Once you’ve fixed the problem, you can merge that branch with the fix back into your development. If you only need to look at it and not make changes, you can choose **Checkout “xxx”…** instead. (These instructions are for Xcode 9. Xcode 8 can do the same thing but you get to them differently. You can also use the command line.)

One thing I do with my apps is to `tag` my release versions with their release number. That makes it trivial for me to go back to an earlier version. There is a **Tag “xxx”…"** option in that right-click menu, though I typically do it from the command line.

Hope that helps!  
-r

---

<div class="post-metadata">

**Author:** ![tw2ocean](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/tw2ocean/32/72102_2.png) [@tw2ocean](https://forums.kodeco.com/u/tw2ocean)\
**Post date:** [September 26, 2017, 9:51pm UTC](https://forums.kodeco.com/t/how-to-use-git-source-control-with-xcode-9/33618/6 "2017-09-26T21:51:14Z")

</div>

Hi I have a question about merging.

Lets say I have set up a branch locally, and then I pushed that branch so that it is also on the remote repository. I have been working on the local repository branch, and have pushed all commits to the remote.

Now I am ready to merge my working branch into the master. If I merge locally, what will happen to the remote? Conversely, If I handle the merge directly at GitHub, what will happen to my local repository?

Thanks in advance,  
Ken

---

<div class="post-metadata">

**Author:** ![rcritz](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/rcritz/32/111201_2.png) [@rcritz](https://forums.kodeco.com/u/rcritz)\
**Post date:** [September 26, 2017, 11:09pm UTC](https://forums.kodeco.com/t/how-to-use-git-source-control-with-xcode-9/33618/7 "2017-09-26T23:09:48Z")

</div>

Hi Ken! Thanks for your question.

The answer in both cases is “nothing happens unless you make it happen.” :] That’s not really helpful, though, so let’s look a little deeper:

**Merge to master locally**

You now need to push your **master** branch to the remote to reflect your changes. Your working branch is now no longer needed and can be deleted. After deleting it locally, you delete it on the remote as well. You can do that in the **Source Control navigator** by twirling down the **Remotes** to find the remote branch, right-clicking and selecting **Delete…** \*. You can also do it in the terminal with `git push -d origin <your branch name>`.

**Merge directly on the remote (e.g. merge a GitHub pull request)**

The **master** branch on the remote now has the most current view of the world. Switch to **master** locally and select **Source Control\Pull…** to fetch those changes. Again, your branch is no longer needed and you can delete it both places.

Neither of these is particularly specific to using git inside Xcode; they are normal day-to-day `git` operations for any kind of project. If you haven’t seen them, let me highly recommend Sam Davies’ “Beginning Git” and “Mastering Git” video courses here on the site. They are excellent and truly helpful, even for folks who use source control all the time.

Hope that helps. Let me know if you have further questions.

-r

---

<div class="post-metadata">

**Author:** ![gamenemesis012](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/gamenemesis012/32/72296_2.png) [@gamenemesis012](https://forums.kodeco.com/u/gamenemesis012)\
**Post date:** [October 2, 2017, 5:42am UTC](https://forums.kodeco.com/t/how-to-use-git-source-control-with-xcode-9/33618/8 "2017-10-02T05:42:14Z")

</div>

Hi,

My question is w.r.t creating local repository and local remote (ssh address based) in Xcode. Don’t want to use git hub server for now.

Before Xcode 9, i used to follow apple’s guide (link below) using local repository and local remotes.

> **[Xcode Server and Continuous Integration Guide: Enable Access to Your Source...](https://developer.apple.com/library/archive/documentation/IDEs/Conceptual/xcode_guide-continuous_integration/PublishYourCodetoaSourceRepository.html)**
>
> Provides guidelines and examples for using Xcode Server and implementing a continuous integration workflow.

But now in Xcode 9 the above apple guide is not applicable.(Setup doesn’t exist in os x sever → Xcode)

---

<div class="post-metadata">

**Author:** ![rcritz](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/rcritz/32/111201_2.png) [@rcritz](https://forums.kodeco.com/u/rcritz)\
**Post date:** [October 4, 2017, 2:03am UTC](https://forums.kodeco.com/t/how-to-use-git-source-control-with-xcode-9/33618/9 "2017-10-04T02:03:35Z")

</div>

I’ve never used Xcode server so I’m not sure what or how it was doing remotes. If I’m understanding what you want correctly, you can achieve it fairly simply from the command line. There is certainly no automated way to do it within Xcode.

In Terminal:

```auto
> mkdir my-repo.git
> cd my-repo.git
> git init --bare
> cd /path/to/local/repo
> git remote add origin user@host:/path/to/my-repo.git

```

You’ll then be able to push to `origin` from within Xcode.

---

<div class="post-metadata">

**Author:** ![gamenemesis012](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/gamenemesis012/32/72296_2.png) [@gamenemesis012](https://forums.kodeco.com/u/gamenemesis012)\
**Post date:** [October 6, 2017, 6:05am UTC](https://forums.kodeco.com/t/how-to-use-git-source-control-with-xcode-9/33618/10 "2017-10-06T06:05:57Z")

</div>

Thanks rcritz for the solution. Also confirming this feature has been deprecated in Xcode 9 .(image snipet from Xcode 9 release note on this issue below).

![IMG_5822](https://raywenderlich-com-v3-forums.s3.amazonaws.com/original/3X/4/3/43489f80758c2828ba439623e0659c184df6cbd9.jpg)

---

<div class="post-metadata">

**Author:** ![kenster999](https://s3.amazonaws.com/cdn.raywenderlich.com/community/forum-assets/noun-game-ghost-878668.png) [@kenster999](https://forums.kodeco.com/u/kenster999)\
**Post date:** [November 19, 2017, 9:06pm UTC](https://forums.kodeco.com/t/how-to-use-git-source-control-with-xcode-9/33618/11 "2017-11-19T21:06:18Z")

</div>

Hi, thanks for the article! I have a question about checking out branches.

Let’s say I start with “master”, then create “branch1” with some changes, and then “branch2” with some changes. All branches have local commits (of course) and have been fully pushed to the remote repository. (I’m using BitBucket, although that shouldn’t matter, I assume, since it implements git.)

Let’s say I’m working on “branch2” and I want to switch to “branch1”. Using the Source Control Navigator, I can choose “Checkout…” on “branch1” under the local (“Branches”) part of the tree. I’ll get a warning stating that "All files in the working copy will switch from the current branch (“branch2”) to “branch1”. This makes perfect sense, so I confirm it by clicking the “Checkout” button. My working copy files are switched to the branch1 files as expected. So far so good.

Now here’s the problem. In the Navigator, under the “Remotes” section, I control-click on “branch1” and choose “Checkout…” I get the exact same warning about working files being updated; this is what I want, so I click “Checkout” to confirm and proceed. But then I get an error, stating “The branch could not be created because one named “branch1” already exists.”

I don’t understand why this happens. Of course branch1 already exists – the Navigator is already showing it in the local (“Branches”) subtree.

I’ll also say that I’m assuming that “Checkout” under “Branches” should work exactly the same as “Checkout” under “Remotes.” My gut instinct tells me it should also do a pull, since that is what would be required if I tried to checkout a branch shown only under “Remotes” but not under “Branches.”

I’d appreciate any insight you may have!

Thanks,  
Ken

---

<div class="post-metadata">

**Author:** ![rcritz](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/rcritz/32/111201_2.png) [@rcritz](https://forums.kodeco.com/u/rcritz)\
**Post date:** [November 19, 2017, 9:40pm UTC](https://forums.kodeco.com/t/how-to-use-git-source-control-with-xcode-9/33618/12 "2017-11-19T21:40:26Z")

</div>

Hi Ken! I’m glad you enjoyed the tutorial and found it useful.

The short answer is that your gut instinct is exactly correct: you must do a pull.

You can’t checkout a remote branch using git because you can’t edit the files on the remote directly. Instead, if you try to checkout a remote branch, git will create a local branch and pull the files over. If that local branch already exists, it can’t do that.

If you want to work on the files on a remote branch, you have to pull them to your local branch and work on them locally. If your local branch and the remote branch are out of sync with each other, then you have to merge them (locally) in order to work on the files. Then you push your local files to the remote to bring everything back into sync.

I hope that helps!

-r

---

<div class="post-metadata">

**Author:** ![kenster999](https://s3.amazonaws.com/cdn.raywenderlich.com/community/forum-assets/noun-game-ghost-878668.png) [@kenster999](https://forums.kodeco.com/u/kenster999)\
**Post date:** [November 19, 2017, 10:44pm UTC](https://forums.kodeco.com/t/how-to-use-git-source-control-with-xcode-9/33618/13 "2017-11-19T22:44:18Z")

</div>

Thanks for the reply! That makes sense, I’m just surprised that Xcode offers a “Checkout” option under “Remotes” when it knows there is already the same branch locally and it’s just going to immediately give an error. (Would it ever not give an error if the same local branch already exists?)

Thanks again,  
Ken

---

<div class="post-metadata">

**Author:** ![rsch92](https://s3.amazonaws.com/cdn.raywenderlich.com/community/forum-assets/noun-game-ghost-878668.png) [@rsch92](https://forums.kodeco.com/u/rsch92)\
**Post date:** [November 24, 2017, 2:03am UTC](https://forums.kodeco.com/t/how-to-use-git-source-control-with-xcode-9/33618/14 "2017-11-24T02:03:18Z")

</div>

Thanks for guide. For anyone not familiar using Git on the command line, I wanted to mention that you can easily use a remote repository other than Github even though Xcode appears to only have support for Github.

After you create your remote repository (for example on Gitlab), take your repository’s .git url, cd into the root of your project directory using the terminal, and use

`git remote add origin <your .git url>`

And allow keychain to save your credentials, if asked.

Now in Xcode, when you go to `Source Control > Push` it will push to that repository.

---

<div class="post-metadata">

**Author:** ![7stud](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/7stud/32/81494_2.png) [@7stud](https://forums.kodeco.com/u/7stud)\
**Post date:** [December 15, 2017, 4:08am UTC](https://forums.kodeco.com/t/how-to-use-git-source-control-with-xcode-9/33618/15 "2017-12-15T04:08:47Z")

</div>

**Xcode 9.2/iOS 11.2**

I can see the initial commit in the Version Control Editor:

 ![git2](https://raywenderlich-com-v3-forums.s3.amazonaws.com/original/3X/1/c/1c9b58bc8d5126b3bbc0d45b47218840dc517834.png)

However, after the following steps in the tutorial:

> Making Some Commit-ments  
> Committing files is easy! Select Source Control\Commit… from the menu.
> 
> A new window will show, similar to the following:

I see:

 ![git1](https://raywenderlich-com-v3-forums.s3.amazonaws.com/original/3X/6/5/65bf172dfc466dc306235861c63aa76c8409de5e.png)

Okay, _ **after** _ I hit `Source Control>Commit`, I actually have to choose one of the files on the left, then the version editor will show me the diff.

I’ve been playing around some more with `Source Control>Commit`, and I am seeing inconsistent behavior: sometimes I see the Version Editor and a diff without choosing a file on the left, and other times I see `No Version Editor`, and I have to choose a file on the left.

---

<div class="post-metadata">

**Author:** ![vakas](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/vakas/32/105714_2.png) [@vakas](https://forums.kodeco.com/u/vakas)\
**Post date:** [December 18, 2017, 7:09am UTC](https://forums.kodeco.com/t/how-to-use-git-source-control-with-xcode-9/33618/16 "2017-12-18T07:09:02Z")

</div>

![58 PM](https://raywenderlich-com-v3-forums.s3.amazonaws.com/original/3X/1/b/1b685826f698ef02aafb5fe6becf034676a48696.png)  
Should be **Getting Started**

---

<div class="post-metadata">

**Author:** ![micazeve](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/micazeve/32/103912_2.png) [@micazeve](https://forums.kodeco.com/u/micazeve)\
**Post date:** [December 18, 2017, 9:14am UTC](https://forums.kodeco.com/t/how-to-use-git-source-control-with-xcode-9/33618/17 "2017-12-18T09:14:34Z")

</div>

I thinks this is an intended pun, since the main topic here is “Git” 😉

---

<div class="post-metadata">

**Author:** ![rcritz](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/rcritz/32/111201_2.png) [@rcritz](https://forums.kodeco.com/u/rcritz)\
**Post date:** [December 24, 2017, 6:16am UTC](https://forums.kodeco.com/t/how-to-use-git-source-control-with-xcode-9/33618/18 "2017-12-24T06:16:50Z")

</div>

Micazeve is correct; the pun is intentional.

---

<div class="post-metadata">

**Author:** ![rusty\_magnet](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/rusty_magnet/32/81494_2.png) [@rusty\_magnet](https://forums.kodeco.com/u/rusty_magnet)\
**Post date:** [December 31, 2017, 9:14pm UTC](https://forums.kodeco.com/t/how-to-use-git-source-control-with-xcode-9/33618/19 "2017-12-31T21:14:42Z")

</div>

This is a great article. I had started with the xCode 9 + github talk from WWDC video [WWDC17 - Videos - Apple Developer](https://developer.apple.com/videos/play/wwdc2017/405/) but your article was much more helpful.

Please can you offer two pro tips?

**Tip 1 - should I commit my project / workspace settings?**  
you used a manually created .gitignore file from a web template. I am writing C command line apps and I don’t like to add my xCode workspace settings. My goal was to keep my github code tidy. Am I setting myself up for a fall if I ever need to clone on a completely new machine?

**Tip 2 - even though a file may be inside my .gitignore file, it seems I also have to manually de-select files I don’t want sent to my remote repo when using xCode / Source Control / Commit ?**  
There seems to be 3 masters of gitignore.

1. the local, project specific .gitignore file(s)
2. xCode / Preferences / source Control / GIT / has a git ignore section
3. when you select xCode / Source Control / Commit you can select to add a file should be ignored…

---

<div class="post-metadata">

**Author:** ![rcritz](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/rcritz/32/111201_2.png) [@rcritz](https://forums.kodeco.com/u/rcritz)\
**Post date:** [December 31, 2017, 10:12pm UTC](https://forums.kodeco.com/t/how-to-use-git-source-control-with-xcode-9/33618/20 "2017-12-31T22:12:11Z")

</div>

Hi Rusty\_magnet,

I’m glad the tutorial was helpful. That’s always nice to hear!

**Tip 1** :  
If you look at the `.gitignore` that we create, you’ll see it excludes the `xcuserdata` directory. That’s good to exclude because it is truly your personal settings and those can be recreated. You still want to keep your `.xcodeproj` file itself or you’re definitely setting yourself up for some pain in the future. Likewise for any other Xcode-related files/directories that aren’t stored in `xcuserdata`. If you have particularly complicated build schemes, I would also advise making them shared so that they can be stored in the git repo.

**Tip 2** :  
You may be running into a situation where the file was committed to the repo _before_ the `.gitignore` was created. In my experience, files excluded by `.gitignore` that are not already in the repo don’t appear in Xcode’s commit dialog. While I know Xcode has its own preferences for doing ignores, I prefer to use git’s native mechanism: the `.gitignore` file. I find that’s more natural and what most git users are expecting.

Hope that helps. Have a Happy New Year!

[Next page](https://forums.kodeco.com/t/how-to-use-git-source-control-with-xcode-9/33618.md?page=2)
