Moving a submodule
suggest changeOn a current Git, move the submodule and update the index with:
$ git mv old/path/to/module new/path/to/module
The steps below are the same move done by hand. Do not run them after git mv.
- Edit
.gitmodules, change the submodule path, and stage that file withgit add .gitmodules. - If needed, create the parent of the new location:
mkdir -p new/path/to. - Move the contents:
mv -vi old/path/to/module new/path/to/module. - Stage the new path:
git add new/path/to/module. - Remove the old index entry:
git rm --cached old/path/to/module. - Move
.git/modules/old/path/to/moduleto.git/modules/new/path/to/module. - In
.git/modules/new/path/to/module/config, pointworktreeat the new checkout. From that directory the relative path isworktree = ../../../../../../new/path/to/module(one../per directory innew/path/to/module, plus two more to get out of.git/modules). Innew/path/to/module/.git, pointgitdirat the metadata, for examplegitdir: ../../../../.git/modules/new/path/to/module.
git status then looks like this:
# On branch master
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# modified: .gitmodules
# renamed: old/path/to/module -> new/path/to/module
#
- Commit the changes.
This example from Stack Overflow, by Axel Beckert
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents