Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Moving submodules with Git [duplicate]

Is there any way to move submodules within your superproject without removing them first and re-adding them ?

like image 282
rafi Avatar asked Dec 01 '10 10:12

rafi


People also ask

Does git clone pull submodules?

It automatically pulls in the submodule data assuming you have already added the submodules to the parent project. Note that --recurse-submodules and --recursive are equivalent aliases.

How do I move submodule?

Git Submodules Moving a submodule 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 ).

How do I change my submodule location?

Enter the master repository's . git/modules directory, and find the directory corresponding to your submodule. Edit the config file, updating the worktree path so that it points to the new location of the submodule's working directory.

Is using git submodules a good idea?

In most cases, Git submodules are used when your project becomes more complex, and while your project depends on the main Git repository, you might want to keep their change history separate. Using the above as an example, the Room repository depends on the House repository, but they operate separately.


1 Answers

It's similar to how you removing a submodule (see How do I remove a submodule?):

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

Looks like this for me afterwards:

# On branch master
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#       modified:   .gitmodules
#       renamed:    old/parent/submodule -> new/parent/submodule
#
  • Finally commit the changes.
like image 184
Axel Beckert Avatar answered Sep 18 '22 19:09

Axel Beckert