We have several projects in the works that share a majority of their code/config files. The framework we're using has certain directory and file dependencies that limit us to how much we can segregate common code. For example, between 'common', 'projectA', and 'projectB' we might have:
/projectA
/projectB
We currently manage this with 3 Git projects: 'common', 'projectA', and 'projectB', with common files separated out into 'common' and project specific files in their own projects. 'projectA' and 'projectB' have a .gitignore with entries for all common dirs and all common files under each shared dir. A script copies 'common' into the project you want to work in and development is done there. Once a change is done, another script copies all common dirs and common files back into 'common'. Changes to 'common' and to the project can then be seen via 'git status'.
This obviously comes with its headaches of copying back and forth between 'common', keeping .gitignore accurate, and switching branches within 'projectA' and 'projectB'. As we plan for 'projectC-F', though, this approach seems nice as we can avoid merging common changes to N projects.
Looking for advice on how to better maintain this type of structure. Submodules seem undoable given the lack of segregation, unless we did a large number of them. I've seen some promising alternatives using symlinks, but that also comes with it's issues. Any advice would be appreciated.
By using git submodules , you can have an independent repository inside a parent repository. So you have your web and mobile repository and then inside it, in a folder, the shared code repository. If you cd into the shared code folder, you can pull, commit, make branches and push back to the shared code.
Yes. You can put multiple projects in one Git repository but they would need to be on different branches within that repo.
Have you considered git subtree?
Something like this can be done:
git remote add common git://server/common.git
git fetch common
git checkout -b common_branch common/master
git checkout master
git read-tree --prefix=common/ -u common_branch
Read more in the links below:
http://www.kernel.org/pub/software/scm/git/docs/howto/using-merge-subtree.html
http://progit.org/book/ch6-7.html
If you're willing to put the shared code in a separate git repository, you might be interested in git submodules
. A submodule allows you to include a git repo within another repo.
Here are a couple links:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With