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?
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.