I have a git repo and I want to add a submodule to it. Problem is, the submodule exists as a folder inside another repo. Can I add only that folder as a submodule?
In order to add a Git submodule, use the “git submodule add” command and specify the URL of the Git remote repository to be included as a submodule. When adding a Git submodule, your submodule will be staged. As a consequence, you will need to commit your submodule by using the “git commit” command.
In your test repository try creating an additional file at the top level. If you follow your instructions, then you'll also get a copy of that file as well as the directory you want. Remove the 'git sparse-checkout init --cone' but follow all your other instructions, and you'll just get the directory tree you want.
I ended up doing this:
submodules
directory.This way you have default Git submodule behaviour and in your project you only use a subset of the whole submodule.
If you really need to include part of an other repository within the history of your own repo, then the subtree merge strategy is more adequate than submodules.
But in both case, the full repository is linked to your repo, not just one directory.
And partial cloning is not possible.
You could try and isolate that directory in its own repository, and then add it as a submodule, but that means its history will be totally seperated from the repo its was coming from originally.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With