Git submodule

add a submodule

git submodule add [-b <branch>] [-f|--force] [--name <name>] [--] <repository> [<path>]

example:

git submodule add -b master --name wp-theme-twentytwelve git@git.iallex.com:iallex-com/wp-theme-twentytwelve.git wp-content/themes/twentytwelve

remove a submodule

Via the page Git Submodule Tutorial:

To remove a submodule you need to:

  1. Delete the relevant section from the .gitmodules file.
  2. Stage the .gitmodules changes git add .gitmodules
  3. Delete the relevant section from .git/config.
  4. Run git rm --cached path_to_submodule (no trailing slash).
  5. Run rm -rf .git/modules/path_to_submodule
  6. Commit git commit -m "Removed submodule <name>"
  7. Delete the now untracked submodule files rm -rf path_to_submodule

Also can use this script git-delete-submodule

#!/bin/sh

submodule=$1

test -z $submodule && echo "submodule required" 1>&2 && exit 1
test ! -f .gitmodules && echo ".gitmodules file not found" 1>&2 && exit 2

NAME=$(echo $submodule | sed 's/\/$//g')
test -z $(git config --file=.gitmodules submodule.$NAME.url) && echo "submodule not found" 1>&2 && exit 3

git config --remove-section submodule.$NAME
git config --file=.gitmodules --remove-section submodule.$NAME
git rm --cached $NAME