Skip to content

Instantly share code, notes, and snippets.

@nickserv
Created December 16, 2012 20:51
Show Gist options
  • Save nickserv/4312799 to your computer and use it in GitHub Desktop.
Save nickserv/4312799 to your computer and use it in GitHub Desktop.
Cheat Sheet: Git Submodules

##Download a repository with submodules

git clone URL MAIN_REPO_DIR
git submodule init
git submodule update

##Add a submodule

cd MAIN_REPO_DIR
git submodule add SUBMODULE_URL SUBMODULE_DIR
git submodule init
git submodule update
git add SUBMODULE_DIR

##Update a submodule (for everyone)

cd SUBMODULE_DIR
git pull
cd MAIN_REPO_DIR
git add SUBMODULE_DIR

##Remove a submodule

cd MAIN_REPO_DIR
git rm -r --cached SUBMODULE_DIR
rm -r SUBMODULE_DIR
vim .gitmodules #delete the entry for the submodule you just removed

##Update your submodules to the versions the repository has

cd MAIN_REPO_DIR
git submodule update
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment