All I want to do is. . .
. . .use submodules in git.
Description: Helpful commands for working with git submodules.
Contributors:
anschwa
Updated: 10/10/15
How to use submodules in git
.
Cloning Repository with Submodules
There are two ways to do this:
First, clone the repository without fetching the submodule's files:
git clone <repository>
Then, fetch all the submodule data:
git submodule init git submodule update
Or, you can simply do this all at once with:
git clone --recursive <repository>
Removing Submodule
Taken from: David Walsh's Remove a Submodule within git
- Delete the relevant section from the
.gitmodules
file. The section would look similar to:
[submodule "vendor"] path = vendor url = git://github.com/some-user/some-repo.git
- Stage the
.gitmodules
changes via command line using:
git add .gitmodules
- Delete the relevant section from
.git/config
, which will look like:
[submodule "vendor"] url = git://github.com/some-user/some-repo.git
- Run:
git rm --cached path/to/submodule
Don't include a trailing slash, that will lead to an error.
- Run:
rm -rf .git/modules/submodule_name
-
Commit the change:
-
Delete the now untracked submodule files
rm -rf path/to/submodule