Git Submodule

Completed Medium
Start
June 18, 2022
End
June 18, 2022
Period
1Days
PIC
Last Updated
June 18, 2022
Tags
git

sAdd a submodule

git submodule add <repository-to-submodule> <path/name>

Convert a directory under Git management into a submodule

git mv bar bar.bk
git add -A
git add submodule <repository-to-submodule> bar

Update submodules

git submodule update

Remove a submodule

git submodule deinit -f <submodule-name>
git rm -f <submodule-name>
rm -rf .git/modules/<submodule-name>

When git status shows (modified content), here’s how to handle it:

  1. Commit changes inside the submodule
  • Navigate into the submodule directory
  • git add
  • git commit
  1. Push to the submodule’s master branch
  • git push origin master
  1. Check the diff
  • git diff
  1. Commit the updated submodule reference in the parent project
  • git add
  • git commit