"Manually" adding git submodules is pointless

· nat's blog


I thought it was enough to just create a .gitmodules file like this:

 1cat <<EOF > .gitmodules
 2[submodule "mulle-allocator"]
 3        path = stash/mulle-allocator
 4        url = https://github.com/mulle-c/mulle-allocator.git
 5        branch = release
 6[submodule "mulle-data"]
 7        path = stash/mulle-data
 8        url = https://github.com/mulle-c/mulle-data.git
 9        branch = release
10EOF

And then run git submodule update --init --recursive on it. But that's not enough. (Fueling my animosity towards git submodules.)

Actually, you also need to do the following:

1git update-index --add \
2                 --cacheinfo 160000 \
3                 $(git ls-remote https://github.com/mulle-c/mulle-allocator.git release | cut -f1) \
4                 stash/mulle-allocator
5git update-index --add \
6                 --cacheinfo 160000 \
7                 $(git ls-remote https://github.com/mulle-c/mulle-data.git release | cut -f1) \
8                 stash/mulle-data

At this point of course, writing the .gitmodules file by hand is unattractive, since you can then execute these git submodule commands instead:

1git submodule add -f -b release \
2                  --name mulle-allocator \
3                  https://github.com/mulle-c/mulle-allocator.git \
4                  stash/mulle-allocator
5git submodule add -f -b release \
6                  --name mulle-data \
7                  https://github.com/mulle-c/mulle-data.git \
8                  stash/mulle-data

I had to use -f because I have "stash" in my .gitignore file.