Problem:
When working in a git submodule, there's an error message something like this:
fatal: Could not chdir to '../../../../../some-dir': No such file or directory
Though I don't know what exactly caused it in my case, I suspect it was renaming a parent directory of my submodule directory.
Maybe git mv
sidesteps the problem and I didn't use it, or maybe I did use it but it doesn't sidestep the problem... Either way, I ended up with a mess.
Solution:
In my case, the .git
file in the submodule directory is a file, with an entry that points to the actual git repo:
gitdir: ../../../.git/modules/www/path/to/submodule
At that path, there is a git repo, and in that repo is a config
file with an entry for worktree
worktree = ../../../../../www/path/to/submodule
The solution was to fix all those paths.
I had renamed www
to web
, so these are the steps I took:
- In the main repo directory, change the location of the submodule repo:
$ mv .git/modules/www .git/modules/web
- In the submodule repo directory
config
file, change the entry forworktree
:
worktree = ../../../../../web/path/to/submodule
- In the submodule directory
.git
file, change the entry forgitdir
:
../../../.git/modules/web/path/to/submodule
- In the main repo
.git/config
file, change the submodule declaration:
[submodule "web/path/to/submodule"] url = submodule-origin-repo-url
Helped me figure this error…