IMarks IMarks - 4 months ago 22
Git Question

Git/Sourcetree Manage multiple project with the same base

I have a project of three sites with the same base.
The sites are builded in Zend Framework so the structure is as follow:

enter image description here

Only the /application/modules is used as base as the rest (might) contain site specific content.

I want to setup the Git/Sourcetree that i can maintain all the projects at once, my suggestion is to use Subtree but i don't know how to configure that right.

My site structure would be basic at this:


  • Head company:


    • Sub company 1

    • Sub company 2

    • Sub company 3




I've created a repo for all 4 companies (the head and the 3 subs)
How can i put the Base in the Head repo and the styling/config in the Sub repo and manage the base within all three sub repos, see TL;DR for meaning (assuming that pull and push are done right).

TL;DR
What i want to achieve is that i can open the repo of a single site, edit the base and whenever i open a second repo (with pull and pushing done) i get the same base within that repo and continue from there.

I have never used any complex stuff within GIT so it's hard for to configure it right

Answer

Make modules a Git submodule so it can be used in multiple projects.

Each company project would have it's own repository, but in each of those repositories, put a .gitmodules file at the base that looks like this:

[submodule "application/modules"]
    path = application/modules
    url = //path/to/modules/repository

To initialize the modules submodule in each repository run git submodule update --init.

You can then work within the modules repository in any project, commit, and push, then pull those changes into any of the other projects simply by going into that project's modules submodule and running git pull (or by using git submodule foreach git pull from the project's base repository).