tags:

views:

329

answers:

2

Picture the following scenario. I have an iPhone application contained in Xcode project A, and an iPhone application contained project B, each one of these Xcode projects is contained in a separate git repository. There are a bunch of things that I would like to do:

  • Be able to create a library or Framework from parts of project B that I would then use in project A or other projects. How can I create a Framework in Xcode, and then clone it into another project using git, so that any changes I make to the framework are reflected. Ideally the framework would remain part of the larger git repository and Xcode project B.

  • Without creating a framework, how can I do the above, namely, import a part of a git repository (call it B1) into another one A, so that I can still keep on developing and improving B1 as part of B, but can eventually see those changes in A?

  • Last point: is there an easy way to merge two Xcode projects (if they have fairly similar structure) using git, or a recommended way, at least to make it as painless as possible.

+2  A: 

the first two you ask about can be done using

git submodule --add <remote repository>

manpage

As for merging you could try creating git project C with git project A and project B as remote repositories. Assuming no or little overlap in files they might just merge together seamlessly. I think however that submodules is probably a better bet.

Jeremy Wall
+1 Submodule is the way to go here.
googletorp
After reading the manpage for submodule, it seems like it inserts a whole repository, not a part of it. Any way to use submodule only for a subtree of a project. I guess another solution would be to create a separate repository and submodule that, but there is still the problem of creating the extra repo from the initial subtree...
Andres
if all you need is part of the repo there is no reason you can't include the whole repo. Unless you have crazy resource constraints just submodule the whole repo.If that really bothers you then it sounds like the framework should be in a seperate repo and then used as a submodule in all projects using it.
Jeremy Wall
Jeremy, thanks for the response. The reason I didn't want to have a whole repo inside another one is because it would be having an XCode project inside another one, and I don't want to imagine how XCode would choke on that. Probably having the library as a Framework in a separate repo is a good idea. Would there be a way to export a subtree from a git repo, maintaining it's history?Thanks,Andres
Andres
I actually have a current xcode project with 2 submodules containing other xcode projects. It handles them just fine. Even allowing you to set build targets from one as a dependency of build targets in the parent.As to exporting a subtree with history I'm not sure I've never tried. That sounds like another good StackOverflow question :-)
Jeremy Wall
+1  A: 

The best solution I have found to this problem is basically to create a static library out of any code I want to use between the two projects, and then import that from the other Xcode project. Very well explained in this post here: Shared Libraries

This allowed us to keep the repositories separate, but still pull from one another as needed.

Andres