title: Merging after directory got turned into submodule
body: <p>I find that working with git submodules, I often encounter problems merging between commits which do contain a given submodules and those which represent the same code as a normal directory. Small reproducing example:</p>
  
  <pre class="lang-sh prettyprint-override"><code># Create one project, to be used as a subproject later on
  git init a
  cd a
  echo aaa &gt; aa
  git add -A
  git commit -m a1
  cd ..
  
  # Create a second project, containing a as a normal directory initially
  git init b
  cd b
  mkdir a b
  echo aaa &gt; a/aa
  echo bbb &gt; b/bb
  git add -A
  git commit -m b1
  
  # Replace directory with submodule
  git rm -r a
  git submodule add ../a a
  git commit -m b2
  
  # Try to create branch from the pre-submodule state of affairs
  git checkout -b branch HEAD^
  </code></pre>
  
  <p>This already gives an error:</p>
  
  <pre class="lang-none prettyprint-override"><code>error: The following untracked working tree files would be overwritten by checkout:
      a/aa
  Please move or remove them before you can switch branches.
  Aborting
  </code></pre>
  
  <p>In order to avoid the error, I deinitialize all submodules first:</p>
  
  <pre class="lang-sh prettyprint-override"><code># Create feature brach starting at version without submodule
  git submodule deinit .
  git checkout -b branch HEAD^
  echo abc &gt; b/bb
  git commit -a -m b3
  </code></pre>
  
  <p>As you can see, the feature branch is completely unrelated to the submodule, modifying a different set of files. Which makes this whole problem particularly annoying.</p>
  
  <pre class="lang-sh prettyprint-override"><code># Try to merge the feature branch
  git checkout master
  git merge branch
  </code></pre>
  
  <p>This fails again, with an error message I don't fully understand:</p>
  
  <pre class="lang-none prettyprint-override"><code>CONFLICT (file/directory): There is a directory with name a in branch. Adding a as a~HEAD
  Automatic merge failed; fix conflicts and then commit the result.
  </code></pre>
  
  <p>I get the same error if I do a <code>git submodule update --init</code> before the <code>git merge branch</code>. I don't see any <code>a~HEAD</code> anywhere, neither in my directory tree nor in the output from <code>git status</code>, which reads like this:</p>
  
  <pre class="lang-none prettyprint-override"><code>On branch master
  You have unmerged paths.
    (fix conflicts and run "git commit")
  
  Changes to be committed:
  
      modified:   b/bb
  
  Unmerged paths:
    (use "git add &lt;file&gt;..." to mark resolution)
  
      added by us:     a
  </code></pre>
  
  <p>If I do <code>git add a</code> as suggested, I get another error:</p>
  
  <pre class="lang-none prettyprint-override"><code>error: unable to index file a
  fatal: updating files failed
  </code></pre>
  
  <p>If I do <code>git submodules update --init</code> just before the merge, then I can do <code>git add a</code> successfully. But if I forget to do so, and then try doing that after the merge, I receive this error message:</p>
  
  <pre class="lang-none prettyprint-override"><code>Submodule 'a' (…/a) registered for path 'a'
  Skipping unmerged submodule a
  </code></pre>
  
  <p><strong>How do I recover from this situation?</strong> Something other than <code>git merge --abort</code>, since I'd like to use it for things like <code>git rebase</code> as well, and since in some scenarios (don't know how to reproduce) I couldn't even abort the merge cleanly, and had to do a hard reset instead.</p>
  
  <p>How can I avoid it in the first place? Is there some magic setting which makes git do the right thing with submodules vs. directories during merges, so that I don't have to manually post-process a merge which only modifies files unrelated to the submodules?</p>