2

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?

Dmitry Minkovsky
  • 36,185
  • 26
  • 116
  • 160

1 Answers1

2

As long as you keep a directory:

  • as a submodule in one branch
  • as a set of managed files in master

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:

  • detect the checked out branch
  • do the git submodule update --force is appropriate.

Something along the lines of that hook (or this one).

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250