Is it possible to also put the two subdirectories into their own repo?
Yes. That's exactly what a submodule is. What happens when you do that is, git add
of the subdirectory stores the id of the currently-checked-out commit in that directory.
You don't need to use the git submodule
command. There are tasks it does that often need doing, but they're obvious ones, and really almost all of them are straightforward oneliners -- and the ones that aren't, aren't much harder than that. The most useful thing the submodule command does is hoist the actual repository out of the subdirectory and into a handy (and arbitrary) nook in the existing repo, so you can still nuke your worktree with impunity.
Here's how you find all your currently-tracked submodules, regardless of whether you've told the submodule command about them:
git ls-files -s|grep ^16 # ls-files -s output: mode id stage path
All the submodules in a commit, regardless of whether you've told the submodule command about them:
git ls-tree -r $id|grep ^16 # ls-tree -r output: mode type id path
($id
can be e.g. just master
, or @
a.k.a. HEAD
)
Id the tracked state for a submodule
git rev-parse :path/to/it # from index i.e. last add/checkout/reset/etc
git rev-parse $id:path/to/it # from $id, e.g. `master` or `3fac3`
Find out what's currently checked out in a submodule:
(cd "$submodule"; git rev-parse HEAD)
Check out the right commit in a submodule:
(id=`git rev-parse :"$submodule"` && cd "$submodule" && git checkout $id)
... and so forth.
So, what is the submodule command really doing for you? Aside from the hoisting above, the only thing it doesadds is a handy place to keep notes -- for instance, where's the default spot to find those commits? The git submodule
command has settled on .gitmodules
as a good place to store stuff like this. As with all things git, the only thing that matters is the commits. Everything else, .gitmodules
file included, is just handy-but-dispensable notes.