I created a branch in which I converted a path in my repository to a submodule. I haven't merged that work into
master yet. Having finished converting that path to a submodule, I attempted to switch back to
master and got the following error:
The following untracked working tree files would be overwritten by checkout:
[ ... a list of files that are now being managed by a submodule ...]
Makes sense. So, I did
git checkout --force master. Then, when I switched back to the branch that tracks the path with a submodule, that path was empty except for the
.git pointer find that you find in submodules. To get the submodule re-checked out to the commit designated in the index, I need to do
git submodule update --force.
Is there a simpler way to handle this situation?
As long as you keep a directory:
You will have the kind of experience you saw, since
git submodule update isn't automatic.
One workaround would be to maintain two clones (one on master, one on your branch).
The other would be to setup a
post-checkout hook which would:
git submodule update --forceis appropriate.
Something along the lines of that hook (or this one).