title: Git hook for updating Git submodule on branch change
body: <p>I'm working with some old code that makes use of Git submodules. The code has several divergent branches which are actively being used, and each of these branches depends on unfortunately a different revision of the relevant submodules; <a href="http://slopjong.de/2013/06/04/git-why-submodules-are-evil/" rel="nofollow noreferrer">this has made development extremely complicated</a>. One of the problems I face is that, when I switch between branches from e.g. <code>master</code> to <code>newfeature-foo</code> using <code>git checkout newfeature-foo</code>, the state of the submodules remains at that of <code>master</code>, which often causes compile errors and even worse can cause differences in runtime behavior that wreaks havoc with user testing and general sanity.</p>
  
  <p>For example, given the <code>.gitmodules</code> configuration:</p>
  
  <pre><code>[submodule "robotcontroller"]
      path = robotcontroller
      url = https://coolrobots.com/repos/robotcontroller
      branch = master
      ignore = dirty
  </code></pre>
  
  <ul>
  <li>the branch <code>master</code> at commit <em>77d4697</em> has a reference to <code>robotcontroller @ f57d1b3</code></li>
  <li>the branch <code>newfeature-foo</code> at <em>b38d29f</em> has a reference to <code>robotcontroller @ 60b27d4</code></li>
  <li>the branch <code>master</code> at <em>873639f</em> doesn't have the submodule <code>robotcontroller</code> at all</li>
  <li>the branch <code>newfeature-foo</code> at <em>301dca4</em> has a reference to <code>robotcontroller @ bdf5991</code></li>
  </ul>
  
  <p>Is there no way e.g. using Git hooks to force the automatic complete re-checking-out of all submodules listed in a <code>.gitmodules</code> file when it changes on checkout of the "root" Git repository?</p>