Moving a submodule

suggest change

On 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.

  1. Edit .gitmodules, change the submodule path, and stage that file with git add .gitmodules.
  2. If needed, create the parent of the new location: mkdir -p new/path/to.
  3. Move the contents: mv -vi old/path/to/module new/path/to/module.
  4. Stage the new path: git add new/path/to/module.
  5. Remove the old index entry: git rm --cached old/path/to/module.
  6. Move .git/modules/old/path/to/module to .git/modules/new/path/to/module.
  7. In .git/modules/new/path/to/module/config, point worktree at the new checkout. From that directory the relative path is worktree = ../../../../../../new/path/to/module (one ../ per directory in new/path/to/module, plus two more to get out of .git/modules). In new/path/to/module/.git, point gitdir at the metadata, for example gitdir: ../../../../.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
#
  1. Commit the changes.

This example from Stack Overflow, by Axel Beckert

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents