git clone works; git submodule fails "Permission denied"

brunoais picture brunoais · Mar 9, 2018 · Viewed 12k times · Source

On a private repository from gitlab, when I run git clone [email protected]:group/project-submodule.git the clone completes successfully.
As part of the cloning process, I'm asked for the passphrase of my private key.

When I run submodule update --init "group/project-submodule"
It fails with:

Permission denied, please try again. Permission denied, please try again. Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password). fatal: Could not read from remote repository.

While trying to process the submodule getting, I'm not asked for the passphrase for my private key.

(I had to anonymize it)

fatal: clone of '[email protected]:group/project-submodule.git' into submodule path 'C:/Users/user/repos/project-module/project-submodule' failed

I've checked the .gitmodules file and it contains the right data (I think it can be confirmed by the error message).

The main element that calls my attention is that I'm not asked for my private key passphrase. Even weirder because, when I use git clone directly, it runs as expected.

I also already diagnosed by accessing with ssh and it asks me for the passphrase just like it happens when I execute a pull or a clone

Using git for windows "git version 2.16.2.windows.1"

Answer

lukas-reineke picture lukas-reineke · Mar 9, 2018

Git tries to clone the submodule using ssh and not https. If you haven't configured your ssh key this will fail.
You can setup ssh-agent to cache the password for the ssh key and get git to use that. Or change to https.
Git is a bit confusing regarding submodules. They are configured in the .gitmodules file in the directory, but changing the url here from ssh to https won't help. Git uses the url that is configured in .git/config.
Open this file and you will find something like this.

[submodule "project-submodule"]
    url = [email protected]:project-submodule.git

Change this url to the https equivalent and try again.