I have a git repository (A) that includes a library code that I need to reuse in the second repository (B).
My understanding is that git submodule does not allow to import only specific path within a repository, the whole repository needs to be imported. Is this correct?
Because of this, I see two solutions to my problem:
- Have A and B as separate repositories and add a symbolic link from B to a library directory in A.
- Add a new git repository C with the library and import it as a submodule in A and B.
What are the advantages of the second approach? It seems to me that adding a separate repository for a small library is an overkill that can add unnecessary burden to the project maintenance. Is there any better way to solve my problem?
The main idea is build reproducibility: the ability to recover the exact configuration (ie the exact list of labels or SHA1) part of what you used at a specific time to build.
In that context (ability to reproduce the build), submodule (and the solution 2) is preferable to any symlink (which is a shortcut to a directory content, without referring to a specific version).
The other alternative is to externalize the lib, outside of a source control system, into an artifact repository like Nexus, and leave in your project(s) only a reference to the right version of that library to fetch.