I added an example based on the answer of @gturri, i hope it helps someone:
Example
Let's say this is your submodule:
app/
├─ code/
│ ├─ Foo/
│ │ ├─ Bar/
│ │ │ ├─ .git/
│ │ │ ├─ .gitignore
│ │ │ ├─ registration.php
│ │ │ ├─ etc/
│ │ │ │ ├─ modules.xml
│ │ │ ├─ view/
│ │ │ │ ├─ frontend/
│ │ │ │ │ ├─ templates/
│ │ │ │ │ │ ├─ foo.phtml
Your submodule is stored in app/code/Foo/Bar and you need it to be in the exact location in the new repo, then do it like this:
# CD into the submodule
cd app/code/Foo/Bar
# Create the same directory tree as the current submodule path, in your submodule
mkdir -p app/code/Foo/Bar
Pro Tip: Use git submodule foreach 'mkdir -p "$sm_path"'
to automatically create the directory structure in all submodules.
See Documentation
New Directory added:
app/
├─ code/
│ ├─ Foo/
│ │ ├─ Bar/
│ │ │ ├─ .git/
│ │ │ ├─ .gitignore
│ │ │ ├─ registration.php
│ │ │ ├─ etc/
│ │ │ │ ├─ modules.xml
│ │ │ ├─ view/
│ │ │ │ ├─ frontend/
│ │ │ │ │ ├─ templates/
│ │ │ │ │ │ ├─ foo.phtml
│ │ │ ├─ app/
│ │ │ │ ├─ code/
│ │ │ │ │ ├─ Foo/
│ │ │ │ │ │ ├─ Bar/
Move files to new folder via GIT:
git checkout <target_branch>
git pull
git mv .gitignore registration.php etc/ view/ app/code/Foo/Bar
git commit -am "Moved files"
git push
Now it looks like this:
app/
├─ code/
│ ├─ Foo/
│ │ ├─ Bar/
│ │ │ ├─ .git/
│ │ │ ├─ app/
│ │ │ │ ├─ code/
│ │ │ │ │ ├─ Foo/
│ │ │ │ │ │ ├─ Bar/
│ │ │ │ | │ │ ├─ .gitignore
│ │ │ │ | │ │ ├─ registration.php
│ │ │ │ | │ │ ├─ etc/
│ │ │ │ | │ │ | ├─ modules.xml
│ │ │ │ | │ │ ├─ view/
│ │ │ │ | │ │ | ├─ frontend/
│ │ │ │ | │ │ │ | ├─ templates/
│ │ │ │ | │ │ | │ │ ├─ foo.phtml
Delete submodule folder:
rm -rf <my_repo_root>/app/code/Foo/Bar
Merge your submodule to your repo:
cd myRepoRoot
git remote add sub <url_to_submodule>
git fetch sub
git merge sub/master
Your submodule should now be located in your repository at app/code/Foo/Bar