Moving a submodule

suggest change

Run:

$ git mv old/path/to/module new/path/to/module
  1. Edit .gitmodules and change the path of the submodule appropriately, and put it in the index with git add .gitmodules.
  2. If needed, create the parent directory of the new location of the submodule (mkdir -p new/path/to).
  3. Move all content from the old to the new directory (mv -vi old/path/to/module new/path/to/submodule).
  4. Make sure Git tracks this directory (git add new/path/to).
  5. Remove the old directory with git rm –cached old/path/to/module.
  6. Move the directory .git/modules/old/path/to/module with all its content to .git/modules/new/path/to/module.
  7. Edit the .git/modules/new/path/to/config file, make sure that worktree item points to the new locations, so in this example it should be worktree = ../../../../../old/path/to/module. Typically there should be two more .. then directories in the direct path in that place. . Edit the file new/path/to/module/.git, make sure that the path in it points to the correct new location inside the main project .git folder, so in this example gitdir: ../../../.git/modules/new/path/to/module.

    git status output looks like this afterwards:

    # On branch master
    # Changes to be committed:
    #   (use "git reset HEAD <file>..." to unstage)
    #
    #       modified:   .gitmodules
    #       renamed:    old/path/to/submodule -> new/path/to/submodule
    #
  8. Finally, 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