Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git nested repositories - submodules vs. symbolic links vs. other

Tags:

git

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."

like image 318
jsuggs Avatar asked Jul 13 '10 01:07

jsuggs


People also ask

Are git submodules a good idea?

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.

When should you use submodules?

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.

What are git submodules?

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.

Can you commit to a submodule?

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.


1 Answers

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:

  • the exact version of that sub component zf2 stored within your project (including a different one for production deployment, if you want to manage a "prod" branch),
  • the ability to change/modify zf2 directly from /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).
like image 73
VonC Avatar answered Nov 10 '22 14:11

VonC