Heesung Yang

Git Submodule Cheatsheet

Add submodule

# see submodule list
~$ git submodule

# add submodule
~$ git submodule add <remote repository> <local dir>

Update submodule

# before git 1.8
~$ cd project # git repository
~$ cd sub1    # assume sub1 is submodule
~$ git pull   # get latest sub1
~$ cd ..
~$ git add sub1
~$ git commit -m 'update submodule'

# after git 1.8
~$ cd project
~$ git submodule update --remote --merge

Remove submodule

~$ SUBMODULE_DIR=themes/ananke/
~$ git submodule deinit -f $SUBMODULE_DIR
~$ git rm -rf $SUBMODULE_DIR
~$ rm -rf .git/modules/$SUBMODULE_DIR

Next post

Git Tag Cheatsheet