0

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.

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Ok @Aasmund so if create submodules of core classes "like a library" from my master project, that why if I make changes to those core classes I can keep those separate repos up to date. Sounds like a nice strategy. Thanks, Accepted, chocolate muffin sent!
So I would need to separate the file structure those files into a folder and add and commit them, or can I create a submodule from a local git repo then add and commit. Then when I am in the other project I can use the git submodule add ["git_repo_url/new_sub_project"] to checkout it to that other project?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.