12

I have a git repository with submodules in the directory projects/myRepo and I want to rename the directory to projects/my-repo.

According to this question it can simply be done with mv. But in a repo with submodules git keeps telling me

fatal: Not a git repository: projects/myRepo/.git/path/to/submodule```

even for git status.

Submodule config:

[submodule "path/to/submodule"]  
   path = path/to/submodule  
   url = https://github.com/user/projectName.git  

Somehow the 'internal path' for the submodule does not get updated?! Is there a way to tell git to update these submodule paths?

CharlesB
  • 86,532
  • 28
  • 194
  • 218
schmunk
  • 4,708
  • 1
  • 27
  • 50
  • That should just work. What's in the .gitmodule file? – Weston Mar 26 '12 at 20:29
  • @Weston, please see my updated question. But even when I remove this section it from the .gitmodules file the same error appears. When I rename the parent dir back to the original name git does no longer complain. – schmunk Mar 26 '12 at 21:51
  • Hmm.. I just tried making a test repo with a submodule. Then I cloned it, init'ed and updated the submodule in the clone, and then renamed the clone with mv. All seems to work as expected...? – Weston Mar 27 '12 at 06:54
  • Yes, I tried the same with a fresh clone, which also worked without problems - it's just that particular repo, see also http://stackoverflow.com/questions/9878860/how-can-i-rename-a-git-repository-with-submodules#comment12628515_9885513 – schmunk Mar 27 '12 at 22:24

4 Answers4

3

I also had the same error after changing my project directory. I have an iOS 6 XCode 4 project but that shouldn't matter.

For each submodule, you need to change the absolute path that it thinks it's in. The path is set in the .git file for that submodule. .git in a submodule is a file as opposed to a directory in a standard git directory.

For each submodule, change the .gitdir line in the .git file. Here is an example from my project:

File: /path/to/project/submodules/RestKit/.git

Before gitdir: /path/to/project//.git/modules/submodules/RestKit

After gitdir: /path/to/project//.git/modules/submodules/RestKit

Jon Deokule
  • 1,506
  • 2
  • 12
  • 7
  • 2
    I also had to change my **worktree** path in .git/modules/path/to/project/submodules/RestKit/config – tuxinaut May 30 '13 at 12:52
3

I did experience exactly the same behavior. I managed to fix it by deleting directories with submodules, recreating them as empty directories with the right name and then running git submodule update --init to reinitialize them. All fixed now. Probably some permission problems (I retrieved those directories from backup earlier and permissions on them are sometimes strange).

Honza Javorek
  • 8,566
  • 8
  • 47
  • 66
1

Today I had the same problem to rename the submodule and finally I fixed it by using the following steps:

Assume the old module name is old/module and the new one is new/module/path

  1. at the root of the repo (repo_root), mv old/module new/module/path
  2. go to .git/modules
    1. mv old/module new/module/path (create the folder first if necessary)
    2. change new/module/name/config: update the worktree entry. It should be the relative path from this config file to repo_root/new/module/path
  3. go to repo_root and edit new/module/path/.git, change the gitdir to the relative path from this file to repo_root/.git/modules/new/module/path
  4. change .git/config of the master repo: find the line containing [submodule "old/module"] and update to [submodule "new/module/path"]
doraemon
  • 2,296
  • 1
  • 17
  • 36
0

Since Weston's test (clone, init and update of a submodule in a cloned repo) worked as expected when renaming the directory including said submodule, I suspect something must have been wrong in the submodule .git itself in your original Git repo submodule.

You could compare/look for any file referencing 'myRepo' in that first submodule.
you can also compare the content of the two submodules (the first one you tried to rename, and the second one included in the repo that you cloned)

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Please note the names here.. I, not the OP, made said test. :-) But maybe OP should make the same test to verify his installation. – Weston Mar 27 '12 at 09:31
  • @Weston sorry, I wasn't completely awake when I wrote this ;) – VonC Mar 27 '12 at 11:10
  • I wasn't able to reproduce the problem, so I think I messed something up while refactoring the project. If I got the time I'll investigate the broken repo, until then I created a new clone, which works fine. Thanks for your help. – schmunk Mar 27 '12 at 22:22