28

guys, I just used submodule to organize some Git repos, here's the address: repos

I want to move all the submodule into a new directory called repos, for examples, jquery -> repos/jquery.

I change the .gitmodules file, but seems it doesn't work. What should I do?

shawjia
  • 1,707
  • 3
  • 13
  • 11
  • 3
    See "[How do I move an existing git submodule within a git repository?][1]" [1]: http://stackoverflow.com/questions/4604486/how-do-i-move-an-existing-git-submodule-within-a-git-repository – user1338062 May 19 '12 at 08:47

1 Answers1

40

Since git 1.8.5,

git mv old/submod new/submod 

works as expected and does all the plumbing for you. You might want to use git 1.9.3 or newer, because it includes fixes for submodule moving.

Credits: Mike Lowerey from comment below

Original answer

Had the same problem just the moment ago and ended up deleting the submodule reference (as outlined in this article) and recreating it where i wanted it to go.

To follow your example of moving submodule jquery into repos/jquery

  1. Delete the (typically three lines) submodule reference from .gitmodules.
  2. Check .git/config for references to the submodule and remove them, if existent
  3. do git rm --cached jquery to cut the submodule reference out of the repository
  4. remove the old submodule folder
  5. recreate you submodule reference (as you possibly did before) with git submodule add git://github.com/jquery/jquery.git repos/jquery

In case your submodule was set to specific tag, respectively commit (which you'll surely have in a stable project) you will have set it again.

Due to this complex process i am strongly hoping there is (or will be, at least on the git roadmap) a more straightforward way of achieving this. If not, surely some scripts could be fumbled together to do this quicker...

Sridhar Sarnobat
  • 25,183
  • 12
  • 93
  • 106
Philzen
  • 3,945
  • 30
  • 46
  • 23
    Since git 1.8.5, `git mv old/submod new/submod` works as expected and does all the plumbing for you. You might want to use git 1.9.3 or newer, because it includes fixes for submodule moving. [(Source)](https://stackoverflow.com/questions/4604486/how-do-i-move-an-existing-git-submodule-within-a-git-repository). – Mike Lowery Nov 07 '19 at 00:02