elliotrock
elliotrock

Reputation: 3420

Git strategies - master xcode project to different projects

I wonder what the best Git strategy is if you are building different xcode projects off a master project. So they use the same core classes but maybe different assets and perhaps different views? Any major changes are always committed/merged back into the master project.

Do I create new xcode project then check out base classes, including the AppDelegate, create a branch or a clone?

Any other strategies? Part of where I want to head is creating a major part of this master project as a SDK so any ideas heading to that point are appreciated.

Upvotes: 0

Views: 52

Answers (1)

Aasmund Eldhuset
Aasmund Eldhuset

Reputation: 38010

You might want to use submodules, which will let you keep your common code in a git repository that can be incorporated into other repositories. The top-level repository won't track the individual files in the submodule, it will think of the entire submodule as one file and only track which commit HEAD points to in the submodule.

Edit (based on your comments): I suppose you already have a git repo containing both a "regular" project and the common code. I suggest the following steps:

  1. Move common files to a separate directory (with whichever nested directory structure you want to have for your common files). Commit this.
  2. Remove the files in that directory from the "regular" (henceforth called "top-level") git repo, without deleting them: git rm --cached -r commonDirectory
  3. cd commonDirectory and git init .
  4. Copy the .gitignore from the top-level repo if you have one, and add and commit all non-ignored files in commonDirectory to the new repo. You now have one git repository living inside another, but it's not a submodule yet.
  5. cd into the top-level repository, run git submodule add commonDirectory, and commit that (together with the removal of all the files in commonDirectory).
  6. Push your submodule repo as a new repo to whichever git server you're using.

Note that there are some subtleties related to cloning repositories that contain submodules.

Upvotes: 1

Related Questions