1

Initial Situation / Goal

I have a GIT repository with a submodule let's say under <root>/Modules/SomePath/Example.

I want to move this submodule to a new location, let's say <root>/LocalStuff/NewName.

What I did

I basically followed How do I move an existing Git submodule within a Git repository and

  • created folder <root>/LocalStuff/NewName

  • used git mv /Modules/SomePath/Example/* /LocalStuff/NewName/

  • in .gitmodules changed from

    [submodule "Modules/SomePath/Example"]
        path = Modules/SomePath/Example
        url = xxxxxxxxx
    

    to

    [submodule "LocalStuff/NewName"]
        path = LocalStuff/NewName
        url = xxxxxxxxx
    
  • in the now LocalStuff/NewName/.git changed from

    gitdir: ../../.git/modules/Modules/SomePath/Example
    

    to

    gitdir: ../../.git/modules/LocalStuff/NewName
    
  • created according folder <root>/.git/modules/LocalStuff/NewName

  • moved all content from <root>/.git/modules/Modules/SomePath/Example into <root>/.git/modules/LocalStuff/NewName

  • in the now <root>/.get/modules/LocalStuff/NewName/config

changed from

worktree = ../../../../Modules/SomePath/Example

to

worktree = ../../../../LocalStuff/NewName

Issue / Question

At first glance this worked fine and when I clone my branch everything is fine.

However, when switching between the "main" branch and my "MoveSubmodule" branch forth and back I get a warning

warning: unable to rmdir 'LocalStuff/NewName': Directory not empty

or accordingly

warning: unable to rmdir 'Modules/SomePath/Example': Directory not empty

with the result that the submodule is only there once but its content is there twice in the two locations. They are not tracked in GIT as changes though so even if I again delete them manually this is not a change I can commit.

Have I missed / screwed up anything?

derHugo
  • 83,094
  • 9
  • 75
  • 115
  • The best way to avoid redundancy with git submodules is the same as the solution for nearly all problems with submodules. Namely, stop using submodules! They are a kludge on a hack on a bandaid over a scab. Use proper dependency management and deployment tools! – William Pursell Feb 25 '22 at 15:16
  • You haven't really missed anything. Submodules have a lot of "user experience" issues and this is one of them. Some call them *sob*-modules; this is part of why. – torek Feb 25 '22 at 21:57

0 Answers0