Question

in Xcode 4 how to associate a project to the local Git repository I set up?

That is:

  • I've set up a Git repository after the Xcode 4 project was already created, based on instructions here:
  • I've gone to Organizer and "added" this as a local Git repository
  • When I go to my project in Xcode 4 the source code functions still don't appear to work - I'm guessing it because there must be some way of tying the Xcode Project wiht the local repository I created?
Was it helpful?

Solution

From "How to Create Git Repos for Existing Xcode Projects":

UPDATE: Apparently just initializing an empty repository in the project directory is enough; Xcode autodetects it for you.
It be nice if something to that effect was in the documentation. Thanks to Jason for that (details here). Open the project directory in a terminal and type the following:

git init
git add .
git commit -m "Initial commit"

So in your case, it should detect it.

The OP Greg comments:

I found out that all I had to do was change a file, and then the Xcode 4 pop up menu for the file did show a source control set of options (previously greyed out).
So the initial part of the answer is correct re the manual git commands for creating the git repository.


Otherwise you can try:

  • make a new XCode4 project with a(n empty) git repo in it
  • move your .git directory and override the Xcode 4 project .git
  • move the sources in that new Xcode 4 project directory
  • see if XCode4 then detect your sources and the Git integration

Not your case probably, but one of the comments mentions:

If you're switching from an SVN repository (which I was), the trick is to go into your project folder and delete or rename the .svn directory.
For me it seemed that Xcode would find the .svn folder first (or preferred it, even though the backing repository was decommissioned), but once it was gone Xcode would happily start using the git repository.

That was actually the issue for another Xcode 4 Git user here on SO.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top