How To Use Git Source Control with Xcode 9

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