Is there any way to move submodules within your superproject without removing them first and re-adding them ?
Asked
Active
Viewed 4,745 times
9
-
This was asked in 2010. The question you linked is from 2011 – rafi Apr 30 '12 at 10:55
-
Sure, but the other question is also much more “popular” (e.g. it has over three times the views; it and its answers have garnered many more votes–even the accepted, identical answer). Anyway, it does not matter much since any close votes expired long ago. – Chris Johnsen Apr 30 '12 at 22:12
-
This question was also asked here: http://stackoverflow.com/questions/4604486/how-do-i-move-an-existing-git-submodule-within-a-git-repository – 5tephenBennett May 02 '12 at 09:48
2 Answers
5
It's similar to how you removing a submodule (see How do I remove a submodule?):
- Edit .gitmodules and change the path of the submodule appropriately, and put it in the index with
git add .gitmodules
- If needed, create the parent directory of the new location of the submodule:
mkdir -p new/parent
- Move all content from the old to the new directory:
mv -vi old/parent/submodule new/parent/submodule
- Remove the old directory with
git rm --cached old/parent/submodule
Looks like this for me afterwards:
# On branch master
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# modified: .gitmodules
# renamed: old/parent/submodule -> new/parent/submodule
#
- Finally commit the changes.

Community
- 1
- 1

Axel Beckert
- 6,814
- 1
- 22
- 23
-
4
-
1
-
3Didn't work for me either; `new/parent/submodule` showed up as an untracked file, `old/parent/submodule` as deleted. I ended up removing & readding the submodule – wutz Nov 07 '11 at 11:48
-
1
1
I don't think there is for now.
There is a patch in the making for a teaching "git mv
" how to handle moving submodules, including how to update the .gitmodules
file.
But it is not there yet.
Simply switching a remote repo for an existing submodule is simpler, but not what you want.

VonC
- 1,262,500
- 529
- 4,410
- 5,250