I'm cloning a repository with a few submodules. In order to save time I'm doing a shallow clone passing the private key as environment variable. Example:
GIT_SSH_COMMAND="ssh -i temp_pvt_key.key" git clone -b my_branch --depth=1 git@my-repo.com:my_team/my_repo.git temp_repo
The command above works just fine! But when I try do the same with submodules adding the --depth=1
, git is not able to find the temp_pvt_key.key
anymore.
Error:
Cloning into 'C:/path/to/submodule/folder'...
Warning: Identity file ../temp_pvt_key.key not accessible: No such file or directory.
git@my-repo.com: Permission denied (publickey).
fatal: Could not read from remote repository.
I'm using relative path (../
) once the private key file is in the repository parent folder.
Works but the whole submodule repository is cloned:
cd temp_repo
GIT_SSH_COMMAND="ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i ../temp_pvt_key.key" git submodule update --init
Basically the same command plus --depth=1. This does not work at all:
cd temp_repo
GIT_SSH_COMMAND="ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i ../temp_pvt_key.key" git submodule update --depth=1 --init
I've tried in a single command too but no success, I ended up with the same error:
GIT_SSH_COMMAND="ssh -i temp_pvt_key.key" git clone -b my_branch --depth=1 --recursive --shallow-submodules git@my-repo.com:my_team/my_repo.git temp_repo
Could I workaround this problem somehow?
Git version: git version 2.19.2.windows.1