8

I have a Git project. Let's name that Proj.

Proj has two submodules, Lib and Utils.

Lib also has the submodule Utils.

Now the problem is, when one wants to git clone --recursive Proj, he will need to download Utils twice. When the project grows deeper, the situation may be worse.

So how can I make Proj reuse the Utils already downloaded by Lib?

My working tree:

Proj                      # Main project
+-- .git
`-- external
    +-- Lib               # Proj depends on Lib
    |   +-- .git
    |   `-- external
    |       `-- Utils     # Lib depends on Utils
    |           `-- .git
    `-- Utils             # Proj also depends on Utils
        `-- .git

Note:

  1. It is better that Utils stays at external/Utils.

  2. Due to Windows compatibility, symlinks are not allowed.

I will appreciate it if anyone can help me with such a complicated question.

Star Brilliant
  • 2,916
  • 24
  • 32
  • 2
    Maybe it would be better to use some kind of dependency management tool. We don't know which technology you're using, but tools like Maven or npm were made for things like this. I don't see a huge benefit in using Git submodules for this - they only get in the way. – nwinkler Feb 23 '15 at 14:01
  • I'm using CMake for a C++ project. `Utils` are some common header files. Will it be a great pain to migrate to Maven? @nwinkler – Star Brilliant Feb 23 '15 at 14:08
  • 2
    Maven is primarily for Java projects, it won't help you with a C++ project. Here are some links to similar discussions: http://stackoverflow.com/questions/1827705/c-buildsystem-with-ability-to-compile-dependencies-beforehand and http://www.reddit.com/r/cpp/comments/2eiulw/dependency_manager_for_ccmake_projects/ – nwinkler Feb 23 '15 at 14:34
  • Thanks for your answer. I will try CMake's ExternalProject module first. @nwinkler – Star Brilliant Feb 23 '15 at 14:36
  • Maybe it can be done with `insteadOf` mechanism (to redirect submodules to local repository)? Maybe I'll try to make a demo. – Vi. Feb 23 '15 at 16:47
  • possible duplicate of [Git: Possible to use same submodule working copy by multiple projects?](http://stackoverflow.com/questions/27379818/git-possible-to-use-same-submodule-working-copy-by-multiple-projects) – jthill Feb 23 '15 at 17:30
  • “Due to Windows compatibility, symlinks are not allowed” – why would Windows compatibility prevent you from using symlinks? Git is [capable of storing symbolic links](https://stackoverflow.com/questions/954560/how-does-git-handle-symbolic-links). And Windows, Mac, and Linux all support relative symbolic links, so the link could reference another folder in the project. – Rory O'Kane Jan 23 '18 at 15:50

1 Answers1

0

As previously mentioned in this nice programmers-stackexchange-post, the only way to come around downloading the stuff twice, is creating symlinks to the first instance of your git-submodule.

Community
  • 1
  • 1
Florian Neumann
  • 5,587
  • 1
  • 39
  • 48