Moving a submodule
suggest changeRun:
$ git mv old/path/to/module new/path/to/module
- Edit
.gitmodules
and 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/path/to).
- Move all content from the old to the new directory (mv -vi old/path/to/module new/path/to/submodule).
- Make sure Git tracks this directory (git add new/path/to).
- Remove the old directory with git rm –cached old/path/to/module.
- Move the directory .git/modules/old/path/to/module with all its content to .git/modules/new/path/to/module.
- 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 #
- Finally, 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
4 Undoing
5 Staging
6 Git diff
7 Merging
10 Submodules
11 Aliases
12 Rebasing
14 Branching
15 rev-list
16 Squashing
18 Recovering
19 git clean
21 .mailmap
23 Pulling
24 Hooks
26 Stashing
27 Subtrees
28 Renaming
29 Pushing
30 Internals
31 git-tfs
33 git-svn
34 Archive
37 Show
39 Bundles
42 Blaming
44 Worktrees
45 Git remote
47 git patch
52 TortoiseGit
57 Git rerer
59 git tagging
61 diff tree
62 Contributors