diff --git a/snippets/add-submodule.md b/snippets/add-submodule.md new file mode 100644 index 000000000..186f9e36a --- /dev/null +++ b/snippets/add-submodule.md @@ -0,0 +1,18 @@ +--- +title: Add a submodule +tags: repository,submodule,advanced +--- + +Adds a new submodule to the repository. + +- Use `git submodule add ` to add a new submodule from `` to ``. + +```sh +git submodule add +``` + +```sh +git submodule add https://github.com/30-seconds/30-seconds-of-code ./30code +# Creates the directory `30code` containing the submodule from +# "https://github.com/30-seconds/30-seconds-of-code" +``` diff --git a/snippets/clone-missing-submodules.md b/snippets/clone-missing-submodules.md new file mode 100644 index 000000000..0f10f4735 --- /dev/null +++ b/snippets/clone-missing-submodules.md @@ -0,0 +1,17 @@ +--- +title: Clone missing submodules +tags: repository,submodule,advanced +--- + +Clones missing submodules and checks out commits. + +- Use `git submodule update --init --recursive` to clone missing submodules and checkout commits. + +```sh +git submodule update --init --recursive +``` + +```sh +git submodule update --init --recursive +# Clones missing submodules and checks out commits +``` diff --git a/snippets/delete-submodule.md b/snippets/delete-submodule.md new file mode 100644 index 000000000..f4caaa4f8 --- /dev/null +++ b/snippets/delete-submodule.md @@ -0,0 +1,23 @@ +--- +title: Delete a submodule +tags: repository,submodule,advanced +--- + +Deletes a submodule from the repository. + +- Use `git submodule deinit -f -- ` to unregister the specified ``. +- Use `rm -rf .git/modules/` to remove the directory of the submodule. +- Use `git rm -f ` to remove the working tree of the submodule. + +```sh +git submodule deinit -f -- +rm -rf .git/modules/ +git rm -f +``` + +```sh +git submodule deinit -f -- 30code +rm -rf .git/modules/30code +git rm -f 30code +# Removes the `30code` submodule +``` diff --git a/snippets/pull-all-submodules.md b/snippets/pull-all-submodules.md new file mode 100644 index 000000000..c2bf7c127 --- /dev/null +++ b/snippets/pull-all-submodules.md @@ -0,0 +1,17 @@ +--- +title: Pull all submodules from remote +tags: repository,submodule,advanced +--- + +Pulls all submodules from their respective remotes. + +- Use `git submodule update --recursive --remote` to pull all submodules from their respective remotes. + +```sh +git submodule update --recursive --remote +``` + +```sh +git submodule update --recursive --remote +# Pulls all submodules from their respective remotes +```