title: How to `git submodule add` Existing sub Repository?
body: <h3>The Question</h3>
  
  <p>How to add existing sub repository as a submodule in git?</p>
  
  <h3>The Why</h3>
  
  <p>I have a private <code>codespace</code> supermodule with submodules scattered randomly:</p>
  
  <pre><code>codespace (git repo, private)
  ├── Archived_projects (git repos)
  └── Projects
      ├── project-foo (git repo)
      └── project-bar (git repo)
  </code></pre>
  
  <p>Sometimes submodules have commits not ready to be pushed. But I want them to be saved while pushing supermodule <code>codespace</code>.<br>
  <code>codespace</code> is a repo cloned to <a href="http://c9.io" rel="noreferrer">c9.io</a> workspace or other places.</p>
  
  <h3>What I Do</h3>
  
  
  
  <pre class="lang-console prettyprint-override"><code>linus@machine /cygdrive/f/__Storage__/Workspace
  $ git clone https://github.com/octocat/Spoon-Knife.git
  Cloning into 'Spoon-Knife'...
  $ cd Spoon-Knife/
  $ git clone https://github.com/octocat/Spoon-Knife.git ./foo/bar
  Cloning into './foo/bar'...
  $ git add .
  </code></pre>
  
  <p>From <strong>cmd.exe</strong></p>
  
  <pre class="lang-console prettyprint-override"><code>&gt; git submodule add https://github.com/octocat/Spoon-Knife.git ./foo/bar
  'foo/bar' already exists in the index
  &gt; cat .gitmodules
  cat: .gitmodules: No such file or directory
  </code></pre>
  
  <p>From <strong>cygwin.exe</strong> (bash)</p>
  
  <pre class="lang-console prettyprint-override"><code>$ git submodule add https://github.com/octocat/Spoon-Knife.git ./foo/bar
  ': not a valid identifier/Git/mingw64/bin/gettext.sh: line 89: export: `sm_path
  '' already exists in the index
  $ cat .gitmodules
  cat: .gitmodules: No such file or directory
  </code></pre>
  
  <h3>Reference</h3>
  
  <pre class="lang-console prettyprint-override"><code>git submodule [--quiet] add [-b &lt;branch&gt;] [-f|--force] [--name &lt;name&gt;]
                [--reference &lt;repository&gt;] [--depth &lt;depth&gt;] [--] &lt;repository&gt; [&lt;path&gt;]
  
  &lt;repository&gt; is the URL of the new submodule’s origin repository.
  
  &lt;path&gt; is the relative location for the cloned submodule to exist in the superproject. If &lt;path&gt; does not exist, then the
  submodule is created by cloning from the named URL. If &lt;path&gt; does exist and is already a valid Git repository, then this is
  added to the changeset without cloning. This second form is provided to ease creating a new submodule from scratch, and
  presumes the user will later push the submodule to the given URL.
  
  In either case, the given URL is recorded into .gitmodules for use by subsequent users cloning the superproject. If the URL
  is given relative to the superproject’s repository, the presumption is the superproject and submodule repositories will be
  kept together in the same relative location, and only the superproject’s URL needs to be provided: git-submodule will
  correctly locate the submodule using the relative URL in .gitmodules.
  </code></pre>
  
  <p><strong>If <code>&lt;path&gt;</code> does exist and is already a valid Git repository, then this is added to the changeset without cloning.</strong>  </p>
  
  <p>Why this doesn't work in my case?</p>