YavarTechWorks
Published in

YavarTechWorks

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 👇

A quick read about this series

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
Submodule in Git

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 <upstream-path> <local-path># 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 -- <submodule>
rm -rf .git/modules/<submodule>
git rm -f <submodule>
# Example
git submodule deinit -f -- patterns
rm -rf .git/modules/patterns
git rm -f patterns
# Removes the `patterns` submodule

Congratulations!

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Nidhin kumar

Nidhin kumar

502 Followers

As a species, we have an inbuilt need to connect with others to communicate and share.