

But, what if you want to use the same child project in many parent repositories? It wouldn't be feasible to copy the child project into every parent and have to make changes in all of them whenever you update it. The traditional method is just to copy the project to the parent repository. Suppose you want to use a single project as a child project inside a repository.
GIT ADD SUBMODULE MANUAL
$ cp -R /path/to/some/directory /app/vendor/directoryĪ downside of this approach is that it requires a manual download and copy process when the external library is updated.
GIT ADD SUBMODULE CODE
Many frameworks allow the use of “vendored” code which simply copies the source of the reference library into the application’s source tree: $ git clone /path/to/some/directory If you find the usability of submodules to be counter-productive you can vendor the code into the project. While Git submodules are one way to quickly reference external library source, users often run into issues with its nuanced update lifecycle. git/submodules directory please consider if this is acceptable for your particular security requirements.

Since submodule references are stored in plaintext in the. If it’s at all possible to use your language’s preferred dependency resolution mechanisms, you should prefer it to using submodules, which can often be confusing and error-prone. Note that failures to fetch the submodules will cause the build to fail.

Initialized empty Git repository in /tmp/build_2qfce3fkvrug9/FooBar/.git/ > Git submodules detected, installing Submodule 'FooBar' () registered for path 'FooBar' Heroku properly resolves and fetches submodules as part of deployment: $ git push heroku

$ git commit -am "adding a submodule for FooBar" Once a git submodule is added locally you need to commit the new submodule reference to your application repository.
GIT ADD SUBMODULE FULL
This would create a new submodule called FooBar and place a FooBar directory with the full source tree of the library into the lib application directory. Remote: Total 26 (delta 8), reused 19 (delta 5) Remote: Compressing objects: 100% (17/17), done. This provides a mechanism of including an external library’s source into an application’s source tree.įor example, to include the FooBar source into the heroku-rails project, use the git submodule add command. Git submodules are a feature of the Git SCM that allow you to include the contents of one repository within another by simply specifying the referenced repository location. This guide discusses the pros/cons of dependency management with git submodules as well as some alternative approaches to consider to avoid the use of submodules. In these situations you can use git submodules to manually manage external dependencies. Such scenarios include private libraries that aren’t publicly accessible or libraries whose maintainers haven’t packaged them for distribution via the dependency manager. However, in some cases the required third-party libraries can’t be resolved by the dependency manager. Tools like RubyGems, Maven in Java, or Python’s pip are all dependency managers that translate a list of stated application dependencies into the code or binaries the application uses during execution. Most modern applications rely heavily on third party libraries and must specify these dependencies within the application repository itself.
