Judging just from the number of results for "git submodule" here on SO alone, this is clearly a commonly asked and easily confused topic, so I will try to be as precise as possible.
Forgetting everything about updating/committing/branching submodules (which I understand greatly complicates things), why do submodules get emptied each time I change branches? From my current understanding, this makes branches expensive; what if I'm at the airport, and can't easily/cheaply connect? Am I doing something wrong, or there's some development philosophy that I'm not yet aware of?
Examples never hurt:
## make a new project
$> git --version
git version 1.7.5.4
$> mkdir new_proj; cd new_proj; git init
$> touch new_file_1.txt; touch new_file_2.txt
$> git add . && git commit -m "first commit"
## move into some development branch
$> git checkout -b cool_feature
$> <hack hack hack>
# in the middle, I add a submodule
$> git submodule add https://github.com/some/other_proj.git other_proj
$> git submodule update --init
$> ls -lR
new_file_1.txt
new_file_2.txt
other_proj
other_proj/that_file
other_proj/another_file
## I have to go back to master to do some work
$> git checkout master
# Why is other_proj still around?
$> git status
Untracked: other_proj
## Fine, I'll remove it, since I want a clean working copy, because I need to do some work and commits
$> git clean -f -d
$> <work work work>
## Now I'm ready to go back to cool_feature, but my submodules are empty!
$> git checkout cool_feature
At this point, I'm supposed to git submodule update
, but what if I can't/it's expensive (e.g. it's remote, and I don't have internet access/it's slow).
The best workaround I've come up with is to clone all the submodules that I care about into a completely separate location, and then submodule from my local clones; this preserves the cheapness of submodules. Of course, this adds another layer of complexity when you're working on a team. :/