There is no commentSelect some text and then click Comment, or simply add a comment to this page from below to start a discussion.
Commands about Git Submodule
How to list all submodules in project?
git submodule
How to clone a project including submodules?
git clone <repository> <path>
# enter the repo folder.cd <path>
# update submodules in project
git submodule update --init
How to get a clean project including submodules while switching a branch?
# Deinit all submodules so there will leave nothing about submodules# after switch the branch.
git submodule deinit .
# Switch to your target branch.
git checkout <branch>
# Pull all submodules.
git submodule update --init
How to list all status about submodules except specific one?
# Keyword *foreach means that all submodules in this project will do something.
git submodule foreach 'case $name in <path>) ;; *) git status ;; esac'
How to make a bulk change with several submodules?
# There might occur errors, such as the working space is dirty or something else, # you need to resolve, # but it's still a convenient command for a bulk modification.
git submodule foreach 'git add .; git commit -m <msg>; git push'
# Git will syna automatically after change the settings via git submodule.
git submodule set-url -- <path> <repository>
# Instead of command, you can modify .gitmodules file directly.# After the modification you need to execute the command below to sync settings.
git submodule sync
How to change tracking remote branch for a submodule?
git submodule set-branch -b <branch> -- <path>
How to totally remove a submodule in the project?
# Remove the submodule entry from .git/config
git submodule deinit -f -- <path>
# Remove the submodule directory from the superproject's .git/modules directoryrm -rf .git/modules/<path>
# in powershell: rm -Recurse -Force .git/modules/<path># Remove the entry in .gitmodules and remove the submodule directory located at path/to/submodule
git rm -f <path>
How to totally remove all submdoules?
# deinit all submodules from .gitmodules
git submodule deinit -f .
# remove all submodules (`git rm`) from .gitmodules
git submodule | cut -c43- | whileread -r line; do (git rm"$line"); done# delete all submodule sections from .git/config (`git config --local --remove-section`) by fetching those from .git/config
git config --local -l | grep submodule | sed -e 's/^\(submodule\.[^.]*\)\(.*\)/\1/g' | whileread -r line; do (git config --local --remove-section "$line"); done# manually remove leftoversrm .gitmodules
rm -rf .git/modules