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.

Git.png

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 git@example.com/the-repo ./the-repo

Get submodules

During clone

git clone --recursive git@example.org:repo

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 Zhiqiang Ma

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 *