Xcode 4 + git (part 1)
Xcode 4 + git (part 1)
- Subject: Xcode 4 + git (part 1)
- From: Quincey Morris <email@hidden>
- Date: Wed, 23 Mar 2011 12:13:39 -0700
After spending something over 12 hours yesterday trying to get Xcode 4 working with a remote git repository, I thought I'd share my findings, in case they help someone else.
I was trying to create a new remote repository on Beanstalk and put an Xcode 4 project in it (which, for git, means getting Xcode4 to understand both the local and remote versions of the project).
Remember that a (SVN) "repository" in Xcode 3 was just a binding between a local project and a subpath within a remote repository. You could have several repositories listed in Xcode 3's Repositories window that all lived in the same real remote repository. The problem with that approach is that it doesn't give you a local way to administer the real repository. In Xcode 3, there were enough SCM functions to do some of it, but it was terribly fragile. (Spoiler: Xcode 4 is worse.)
I started with my first mistake, which was to create a workspace. (I originally intended to create a set of projects under an Xcode 4 workspace umbrella. Ha!) If you want to work with git, you can pretty much forget about workspaces being integrated into that workflow. I'll come back to this point later.
So I had an empty Beanstalk git repository, and I had Xcode 4. How could I get a project into that repository? AFAICT there's nothing in the Xcode 4 documentation that helps. It tells you how to create a new Xcode project with a local git repository; it tells you how to import a project from an existing local git repository; and it tells you how to import a project that exists in a remote git repository (creating a local repository along the way) -- though it irritatingly side-steps some key points by telling you to mount the server in the Finder, which isn't much help with something like Beanstalk -- but it *never* says how to get the project into the remote repository.
After a lot of trial and error, here's what (I think) I did. Everything is qualified with "I think" because I kept trying things randomly, and may not have realized which thing was actually the correct one.
1. Create a local repository under git control.
This *almost* works as advertised. I ran into a problem where Xcode 4 would tell me it couldn't use git for the new project because a git repository already existed in that folder -- in spite of the fact that I just created the folder. I think it confused either the project name or the folder name with the name of something I had opened earlier. In the end, I solved this by removing all traces of my earlier attempts from the Projects tab of the organizer (to delete the derived data directories), quitting Xcode, removing folders of partially created project crap and starting Xcode again.
2. Using Terminal, have git put the remote server information into the local repository. The command looks like this:
git remote add beanstalk email@hidden:/repository.git
I got that from Beanstalk's excellent, accurate and simple documentation on how to set up a git repository. (The contrast in usability of Beanstalk's instructions and Xcode 4's was startling. Not in a good way for Xcode 4. It's a pity Beanstalk doesn't give the Xcode 4-specific part of the instructions too.)
3. Using terminal, push the local repository back to the server. The command for this is:
git push beanstalk master
("master" is the name of the initial branch.) This command also came from the excellent Beanstalk instructions. Before you do this, though, you should probably tell git your name and email address, otherwise it will commit with the defaults it plucks out of thin air. The commands for this are:
git config --global user.name "My Name"
git config --global user.email email@hidden
Credit goes to git itself for telling me to do this, although it didn't tell me until after it had used the wrong ones. Go figure! You only ever have to do this once.
4. In the Xcode 4 repository window, choose Checkout or Clone Repository… from the menu on the "+" button at the bottom left. That brings up a sheet with a Location field.
5. Paste the repository path into this field. Again, Beanstalk made this easy, because in its repository browser and repository setup pages, it shows the correct URL *and* has a button to click to put it on the clipboard without even having to select the damn text. :) The URL looks like this:
email@hidden:/repository.git
6. An aside:
As part of the Beanstalk instructions, you create yourself a SSH public/private key pair in your home directory, because you're going to access the repository via SSH. That means (apparently) that you'll always use username "git" to access your repository (see that username in the URL above?). There's no password because the security comes from SSH. It's a slightly obscure way of doing it, but it's fine. Just keep in mind that Xcode 4 will show "git" and no password, when it later creates an otherwise apparently useless Repositories tab entry in the Organizer for the repository as a whole.
7. When you paste in the URL, Xcode tries to contact the server, says it succeeds, and changes the text you pasted into this:
ssh://email@hidden//repository.git
(Note that it doesn't validate anything here. I just pasted literally this into that text field, and it says the host is reachable, even though my account name isn't "account" and I don't have repository called "repository".)
8. ** Really important step **
(continued, at this point of high suspense, in a second post, because I think the whole story is too long for a single post)
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden