I've asked this question myself for a thousand times now but I can't seem to find the correct answer.

I'd like to separate a part of reusable code from the actual project however both the project and the reusable code part need each other.

Let's give an example. I've setup a working CMS which has it's own git repository. I have a catalog module which also has it's own git repository. Now I'd like to integrate the catalog module into my CMS git repository. To do so I currently use copy/paste which results in the same code in two places. I now notice a bug in the module whilst I'm running the CMS git repo and adding a product.

Currently to fix this bug, I've to make changes at two places: The working git repository and the separate catalog module so the next projects will not have this anymore.

Most of the time things are getting lost in copy/pasting etc so I'd like to add the catalog repo to the cms repo through git as a 'submodule', I've read about it but don't seem to get my head around it. So every time I make a change to the cms repo which contains changes to the catalog module I should be able to commit these changes to the other git repository.

If I don't make sense here, please comment and I'll try to explain it better. This is however a problem for me, and probably for many others.

  • "now I do this with copy/paste" You might want to explain why you do this. You're supposed to make the catalog module a library so it can be imported as a dependency in other projects. – Vincent Savard Oct 25 '17 at 12:34
  • 2
    Have you tried to replace copy&past with git submoduls ? – k3b Oct 25 '17 at 12:55
  • I do it with copy paste because I see no other way. Git submodules is indeed my way forward. But I have the problem that my actual module is structured as src/Backend/Modules/{Module_name} and so is my project. But I can't use git submodules in thesame root folder as my main as that would destroy the git functionality I suppose? Because when I add a submodule it stores it in /SubmoduleName and not in the /. Replacing that would destroy the supermodule's git repo. – Ciryk Popeye Oct 25 '17 at 14:06

Your CMS is expecting a certain structure and Git is expecting a certain structure, but the two don't agree. We can either fix one of them, or create a bridge between these structures.

Fixing the structure is only feasible if this is a home-grown CMS. If so, it should be easy to extend so that module can be loaded from many places, not just a specific modules folder in your source tree. You can then use Git submodules.

“Fixing” Git does not seem to be wise because then you'd be using a non-standard tool. You cannot overlay multiple Git repos into the same directory structure.

To bridge between the two structures, you can either create the bridge on a file-system level or on a software architecture level.

On a file system level, you can perhaps use symlinks. Your CMS expects the module at src/backend/Modules/ModuleName, but the module is located at SubmoduleName/src/ModuleName. It might be possible to place a symlink from the expected location that points to the actual location. However, this might lead to problems when loading dependencies of the module, or may be prohibited for security reasons. But if this works, this would be a fairly simple solution. Git supports symlinks.

On an architecture level, you could create a dummy module at the required location that can load the actual module and forwards all operations to the actual module. The CMS can then load the dummy module without problem.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.