Git submodule "git fatal: Could not chdir to..."

Submitted by kentr on 07/25/2016, 13:04


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.


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:

  1. In the main repo directory, change the location of the submodule repo:
          $ mv .git/modules/www .git/modules/web
  2. In the submodule repo directory config file, change the entry for worktree:
          worktree = ../../../../../web/path/to/submodule
  3. In the submodule directory .git file, change the entry for gitdir:
  4. In the main repo .git/config file, change the submodule declaration:
          [submodule "web/path/to/submodule"]
        url = submodule-origin-repo-url


Add new comment