Rename Directory Which Contains Submodules

When rename a directory which contains submodule using command git mv old new, and then check status with git status, an error will occur like

fatal: Could not chdir to ‘../../../../../lib/hiredis’: No such file or directory fatal: ‘git status –porcelain’ failed in submodule lib/hiredis

because git won’t rename the path of submodule in the configuration files automatically. Thus we must edit these configs manually.

Here are several files that may contain submodules:

  • .gitmodules
  • .git/config
  • .git/modules/path/of/submodule/config

Alternatively, you can use grep "keyword" . -r to find the origin path of submodule and then replace it manually.

Similarly, replace path using find and xargs command.

$ find . -name .git -type f -print0 -type f | xargs -0 sed -i 's|old|new|g'
$ find . -name .gitmodule -type f -print0 -type f | xargs -0 sed -i 's|old|new|g'
$ find . -name config -print0 -type f | xargs -0 sed -i 's|old|new|g'
comments powered by Disqus