How to move a git submodule / / at 20:31 / / by abe

from the git-rules-and-still-can-be-improved dept.

If you try to move a git submodule with git mv , you’ll get the following error message:

$ git mv old/submodule new/submodule fatal: source directory is empty, source=old/submodule, destination=new/submodule

There’s a patch against git to supoort submodule moving, but it doesn’t seem to be applied yet, at least not in the version which is currently in Debian Sid.

What worked for me to solve this issue was the following (as posted on StackOverflow):

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 new . Move all content from the old to the new directory: mv -vi old/submodule new/submodule . Remove the old directory with git rm --cached old/submodule .

Looked like this for me afterwards:

# On branch master # Changes to be committed: # (use "git reset HEAD <file>..." to unstage) # # modified: .gitmodules # renamed: var/lib/dokuwiki/tpl -> var/lib/dokuwiki/lib/tpl #

Finally commit the changes. HTH.

