Git Error: Fatal: /Usr/Libexec/Git-Core/Git-Submodule Cannot Be Used Without a Working Tree

I have a git repo with a submodule.

I would use in post-receive hook file:

git --git-dir="$GIT_DIR" --work-tree="$GIT_WORKDIR1" submodule update --init --recursive 

but I get the following error:

remote: fatal: /usr/libexec/git-core/git-submodule cannot be used without a working tree.  

I did not get solution for this problem.

What should I do to make it work?

3 Answers

You may see this error if you've renamed the path (working-tree) of a git submodule. In my case I had updated the path in .gitmodules to match my new path and thought I was good. But when I did a git pull later it added new files in the old path. This is because there are two places the module path is defined. You need to also update your "working-tree" as defined in the .git/modules/{modulename}/config file.

There are some great details about the working-tree on this post as well.

1

I got this same error when running git submodule inside of a shell I spawned while I was running git log (with the !bash command). What also confused me was that I could run all git commands if I ran them with sudo, and that this problem affected multiple repos, not only the one I was running git log into.

The solution of course is to exit the subshell and the git log command.

I also stumbled across this issue and found it is caused, because I needed to cd into the workdir first. I am not sure why this is required, maybe it is a git bug? You can also pass the path via -C and set the workdir to .:

git --git-dir="$GIT_DIR" --work-tree=. -C "$GIT_WORKDIR1" submodule update --init --recursive

Also I noticed that in my plesk git user interface (netcup.com) variables do not seems to work, I have to specify absolute paths without variables here:

git --git-dir=/git/repo_name.git --work-tree=. -C /httpdocs/website submodule update --init --recursive

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Maya Lin-Takahashi

Maya Lin-Takahashi

Consumer Tech & Gadget Reviewer

Maya is a hardware enthusiast who tests and reviews smart home devices, smartphones, wearables, and audio gear. She focuses on practical consumer value and build quality.

Share this article
Twitter Facebook Pinterest