Skip to main content

Command Palette

Search for a command to run...

Git for Noob-to-Pro — #4(Module)

Updated
2 min read
Git for Noob-to-Pro — #4(Module)

If you don’t have time to read but want to know what’s there in this series. Find the quick read 👇

On this Series

We are going to see the commonly used Git snippets for the repository which will make you from Noob to Pro.

The Git Repository snippets that we are going to look at in this series are

  1. Local Repository

  2. Branches

  3. Commits

  4. Module

  5. Stash

On this Post

In this post, we are going to see the topic Module which has the following sub-topics like

  1. Add a submodule

  2. Pull all submodules from remote

  3. Clone missing submodules

  4. Delete a submodule

1. Add a submodule

Adds a new submodule to the repository.

  • Use git submodule add <upstream-path> <local-path> to add a new submodule from <upstream-path> to <local-path>.

git submodule add

# Example
git submodule add https://github.com/nidhinkumar06/HTML-LayoutPatterns ./patterns
# Creates the directory `patterns` containing the submodule from
# "https://github.com/nidhinkumar06/HTML-LayoutPatterns"

2. Pull all submodules from remote

Pulls all submodules from their respective remotes.

  • Use git submodule update --recursive --remote to pull all submodules from their respective remotes.

git submodule update --recursive --remote

**# Example
**git submodule update --recursive --remote
# Pulls all submodules from their respective remotes

3. Clone missing submodules

Clones missing submodules and checks out commit.

  • Use git submodule update --init --recursive to clone missing submodules and checkout commits.

git submodule update --init --recursive

# Example
git submodule update --init --recursive
# Clones missing submodules and checks out commits

4. Delete a submodule

Deletes a submodule from the repository.

  • Use git submodule deinit -f -- <submodule> to unregister the specified <submodule>.

  • Use rm -rf .git/modules/<submodule> to remove the directory of the submodule.

  • Use git rm -f <submodule> to remove the working tree of the submodule.

git submodule deinit -f --
rm -rf .git/modules/
git rm -f

**# Example
**git submodule deinit -f -- patterns
rm -rf .git/modules/patterns
git rm -f patterns
# Removes the `patterns` submodule

Congratulations!

More from this blog

Nidhin's blog

163 posts

✨Crafting Code with a Smile for 8 Years:) Merging the Formal Dance of Angular, the Playful Rhythms of React, and the Next-level Moves of Next.js 🚀