Git Submodule Cheat Sheet

I summarize some commonly used commands that I find useful for working with git submodule. For the list of full commands, check the git submodule manual.


In the following commands, I take scala-mode2 as an example as the submodule.

Add a submodule

git submodule init
git submodule status
git submodule add -f ./the-repo

Get submodules

During clone

git clone --recursive

In a cloned repository

git submodule update --init --recursive

Check out the master and update submodules

git submodule foreach --recursive git checkout master
git submodule foreach --recursive git pull

Push the version changes to origin

# cd the git repository first (not in submodule)
git commit -am 'submodule updated'
git push

Delete a submodule

git submodule deinit ./the-repo
git rm ./the-repo

Eric Z Ma

Eric is a father and systems guy. Eric is interested in building high-performance and scalable distributed systems and related technologies. The views or opinions expressed here are solely Eric's own and do not necessarily represent those of any third parties.

Leave a Reply

Your email address will not be published. Required fields are marked *