Git Submodules Cheat Sheet

Features

# Clone a new project and its submodules  
git clone --recursive <MAIN_PROJECT_REPO>
# Create a submodule (& clone it)
# This also creates a .gitmodules file that shouldn't be editted manually
git submodule add <MODULE_REPO> <DIRECTORY>
# Checkout a branch on the submodule
cd <MODULE_REPO>
git checkout <BRANCH_NAME>
# Commit the version
cd ..
git commit -am "<COMMENT>"
git push origin <BRANCH>
# update the submodules
git submodule update
# Git cloning submodules if empty
git submodule update --init --recursive
# Update specific submodule
git submodule update --remote <MODULE_DIRECTORY>
# PULL on all submodules
git submodule foreach git pull origin master
# Update submodules recursively
git submodule update --recursive
# Status of git submodule
git submodule status <PATH_TO_SUBMODULE>
# Modifications to git project
## Want submodule to update after a pull - add to githook
echo "git submodule update --init --recursive" >> .git/hooks/post-merge
## Set up git to show updates to submodules on git status
git config status.submodulesummary 1
## Point the submodule to a branch instead of a commit E.g. master or stable
git config -f .gitmodules submodule.<MODULE_NAME>.branch <BRANCH_NAME>

References

--

--

--

An entry developer wanting to share my knowledge and bring up others. Also an active person just trying to learn from other people mistakes.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Leetcode 315. Count of Smaller Numbers After Self

CPU Components

My coding adventure started in my 30s!

Hadoop Configuration using Ansible !

My experience with vector drawables — some tips

How the pandemic made me fully participate in She Code Africa Mentor-ship Program (Cohort 2).

Getting started with OpenLDAP (Part I)

Project 4: External Sensors

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
Thomas Suebwicha

Thomas Suebwicha

An entry developer wanting to share my knowledge and bring up others. Also an active person just trying to learn from other people mistakes.

More from Medium

I have used only 3 out of these 14 CI/CD tools

Git and GitHub

GitHub gif

Git/GitHub

Most basic Git commads that every programmer must know