'git subodule add' without cloning

How can I add a local submodule to a project without actually cloning all the files it contains? I want to avoid local duplication of project files.

I know that this kind of thing can be achieved, because when you clone a project that includes submodules, they are not cloned by default. You must do it manually:

git clone url-of-repo-containing-submodules.git git submodule init sub-mod git submodule update --remote 

Let's say I have a git repo meta project with out-source lib-sobmodule repository.

I could hack it to avoid duplicate files:

 cd /path/to/metaproject git submodule add ../path/to/lib-sobmodule git commit -m "lib-sobmodule added..." git push cd .. && rm -rf meta-project git clone url-of-meta-project.git 

Tadam! Lib-sobmodule files are not duplicated on my desktop. But this is not a good solution, as it exports and then imports everything to / from a remote git device ...

Is there an option or method that can interfere with cloning a local project without duplicating all the files it contains?

Disclamer: This is almost a clone question. Is there a way to git submodule add repo without cloning? . But since the answers focused on requiring 30K git submodules, they did not provide a satisfactory solution for the more common use case described here.

+6
source share

Source: https://habr.com/ru/post/1015449/


All Articles