Is this useful: Buy me a coffee
I have worked with and created and maintained a number of projects with using git submodules and value the feature and would class myself as an “expert” or at least “proficient” git user and yet every so often when I hit bugs with git submodules that I find irritating. This derives from a lack of undertanding of how git submodules work, but my googling around the topic often results with “how-to pages” telling me how useful git submodules is without really giving me an understanding.
This page of limited scope tries to give a git submodules user sufficient understanding to fix their git submodules problems, while also focusing on submodules.
git submodules
Git submodules is a layer that runs on top of git - this is confusing because it is “half git / half something else” and understanding git submodules require a measure of undestanding of both.
Git submodules often “just works” enough that you don’t need to understand the internals - this means that you don’t naturally buid uip an understanding of git submodules through us.
Despite mostly “just working” sometimes certain things you need to do (particularly when they go wrong) aren’t abstracted over.
.gitmodules
contains information about where git submodules should find this commit. This is committed and shared with other people..gitconfig
contains information about what is actually checked out (this information is not committed) and allows for tweaks..gitmodules
but my repository but git clone still doesn’t workThe repository url is cached in .gitconfig. Use your editor to remove it from .git/config
.
git submodule update
hangs on Cloning into...
Potentially repository that you are cloning from does not exist. You might need to get it running again, or change it.
Proper fix:
.gitmodules
check the url
entry for the submodule in question.git/config
git submodule init $MODULE
to create a new entry git/config
git submodule update $MODULE
to check out the git modulegit add .gitmodules; git commit
git submodule deinit $path
git submodule init $path
.git/config
is too slowYou can use git config
git config | grep submodule
git config --unset submodules.$path