I'm trying to setup my (Zend Framework) development environment (or more importantly my directory structure) with git. However, my underlying question really has nothing to do with the specific libraries involved but more importantly how to get git to accomplish what I am wanting.
I'm going to have my project root be /home/jsuggs/project
.
I'm also going to be working with/on Zend Framework (ZF), Doctrine, and other libraries, but I'll only focus on ZF since the solution for one will likely be the same for the others.
I will clone the ZF2 repository in /home/jsuggs/zf2
.
I would like to have /home/jsuggs/project/application/library/Zend
reference /home/jsuggs/zf2/library/Zend
.
I want the ability to work locally on both repositories (project and zf2), where switching branches in zf2 directly affects project.
My question is how do I setup Git so that the deeply nested libraries can reference my local versions during development but can also be set to (other/arbitrary) locations when deployed into production?
I would also like to avoid having the paths be absolute, so that if someone else worked on the project then the library path wouldn't referencing to my home directory.
I'm looking into using symbolic links and git submodules, but wondered if there were "best practices" for this type of setup. Also, it is completely possible that I am just doing it wrong so feel free to say "just do X instead."
Git submodules may look powerful or cool upfront, but for all the reasons above it is a bad idea to share code using submodules, especially when the code changes frequently. It will be much worse when you have more and more developers working on the same repos.
In most cases, Git submodules are used when your project becomes more complex, and while your project depends on the main Git repository, you might want to keep their change history separate. Using the above as an example, the Room repository depends on the House repository, but they operate separately.
A git submodule is a record within a host git repository that points to a specific commit in another external repository. Submodules are very static and only track specific commits. Submodules do not track git refs or branches and are not automatically updated when the host repository is updated.
Use the git submodule update command to set the submodules to the commit specified by the main repository. This means that if you pull in new changes into the submodules, you need to create a new commit in your main repository in order to track the updates of the nested submodules.
Whenever you need to have a specific configuration (specific revisions) for different set of files, the component-based approach is best.
With symbolic link, you have no idea what exact version of zf2 your project (through the path /home/jsuggs/project/application/library/Zend
) is referencing.
But with submodules, you will have:
prod
" branch),/home/jsuggs/project/application/library/Zend
(provided you commit those changes within zf2, then commit the zf2 new revision within /home/jsuggs/project/application/library
, i.e. your parent project).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