I would like to change the directory name of a Git submodule in my Git superproject.
Lets suppose I have the following entry in my .gitmodules file:
[submodule ".emacs.d/vimpulse"]
path = .emacs.d/vimpulse
url = git://gitorious.org/vimpulse/vimpulse.git
What do I have to type to move the .emacs.d/vimpulse directory to .emacs.d/vendor/vimpulse without deleting it first (explained
here and here) and then re-adding it.
Does Git really need the whole path in the submodule tag
[submodule ".emacs.d/vimpulse"]
or is it also possible to store just the name of the subproject?
[submodule "vimpulse"]
Newer versions of git
Git now has native support for moving submodules:
Older versions of git
As mentioned in the comments, this answer refers to the steps needed with older versions of git.
The process is similar to how you’d remove a submodule (see How do I remove a submodule?):
Edit
.gitmodulesand change the path of the submodule appropriately, and put it in the index withgit 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).Make sure Git tracks this directory (
git add new/parent).Remove the old directory with
git rm --cached old/parent/submodule.Move the directory
.git/modules/old/parent/submodulewith all its content to.git/modules/new/parent/submodule.Edit the
.git/modules/new/parent/configfile, make sure that worktree item points to the new locations, so in this example it should beworktree = ../../../../../new/parent/module. Typically there should be two more..than directories in the direct path in that place.Edit the file
new/parent/module/.git, make sure that the path in it points to the correct new location inside the main project.gitfolder, so in this examplegitdir: ../../../.git/modules/new/parent/submodule.git statusoutput looks like this for me afterwards:Finally, commit the changes.