Git Submodules
15/07/2019
Creating a submodule
Creating a git submodule is pretty easy:
$ git submodule add [path_to_repo] [Name_of_Submodule]
In the below picture, you can see that I created a submodule from a remote repo and put it in the Submodules folder.
What I did was, I created a private repo called TestSubmodules
on GitHub and then created another private repo Repo2
. I added Repo2
as a submodule to TestSubmodules
and as you can see, it moved Repo2
into the
SubmoduleRepo folder
.
I, however, could not add a submodule to a local repository that was on my computer without a remote. (It was worth the test, for science!)
After commiting and pushing up to GitHub, you will see this:
Cloning a repo with a submodule
When cloning a git repo with a submodule, simply cloning with git clone [path_to_git_repo]
will not pull any of the submodules.
Instead, use:
git clone --recursive [path_to_git_repo]
This will pull your submodules as well.
Last updated
Was this helpful?