62

I am not able to clone the submodule existing within my private git repository. I do have access to entire repository,

Have used the below commands but dint work, please help. What is the right way to clone the submodules in an existing repository?

djrecker$ git submodule update --init --recursive
Submodule 'Path' (git@github.com:Path) registered for path 'App'
Cloning into 'Path'...
Permission denied (publickey).
fatal: Could not read from remote repository.
George Mauer
  • 117,483
  • 131
  • 382
  • 612
Max
  • 5,380
  • 6
  • 42
  • 66
  • 1
    Can you clone `git@github.com:Path` independently? Just to check that a direct clone would work and that you do have access. – VonC Sep 21 '14 at 08:03
  • Yes i did that and i get the entire repo except the submodule, – Max Sep 21 '14 at 09:00
  • 3
    Can you check the `.gitmodules` content (in the repo you just cloned), and try cloning the url referenced in it. – VonC Sep 21 '14 at 09:01
  • Can you please tell me how do i do that ? I am a little new to git so please bare with me. – Max Sep 21 '14 at 09:44
  • See if the repo you just cloned has a `.gitmodules` file in it. Then open that file, and try cloning the url(s) listed in it. – VonC Sep 21 '14 at 09:45
  • 1
    As @VonC mentioned, after checking the contents within `.gitmodules`, I see there's a different repo than the main one in which I have to refresh my ssh key. After doing so, it's working. – Ke Li Nov 06 '19 at 21:07

13 Answers13

60

I was facing the same issue. The problem was on your github repo , you might be using some old ssh key.

You need to update the current ssh key.

Steps involved are:

1. vim ~/.ssh/id_rsa.pub
2. copy the ssh key
3. Go to the github settings
4. Select the option ssh keys
5. Remove the old ssh keys not used anymore.
6. Add a new ssh key.
7. Try running the "git submodule update --recursive"

This worked for me !!

arpiagar
  • 4,314
  • 1
  • 19
  • 12
  • I had never configured an ssh key, but everything worked fine after I configured my ssh key – Adam Johns Jan 18 '22 at 20:08
  • Same as @AdamJohns. Github has some guides to generating and adding SSH keys for the uninitiated: Generating keys: https://docs.github.com/en/authentication/connecting-to-github-with-ssh/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent Adding to github: https://docs.github.com/en/authentication/connecting-to-github-with-ssh/adding-a-new-ssh-key-to-your-github-account – user2528534 Apr 06 '23 at 08:58
43
  • On Windows:

In my case, it was complaining about the same issue when I was using a regular command line (Git CMD). Then I tried with Git Bash and no issue no more.

Cem.S
  • 1,001
  • 10
  • 15
20

I had this issue. In my case, the public key (~/.ssh/id_rsa.pub) wasn't set up on the server properly.

Ensure you're getting all the submodules:

Reference: Git update submodules recursively

# This must be called twice. Once for new and once for existing submodules.
git submodule update --init --recursive
git submodule update --recursive

To diagnose permission issues with your key:

To check details of your submodules

  • Open .gitmodules in the project root folder and ensure things look okay. As recommended by @VonC try cloning them in a separate folder.
  • You might want to switch submodules from using SSH to HTTPS. That will let you type a username and password. But that can cause issues with your teammates and build automation. Speak to them first.
SilentSteel
  • 2,344
  • 1
  • 28
  • 28
12

In my case the issue was caused by console which did not ask me for a password. Solution was to change the console from CMDER to Gitbash. When I used CMDER it does not show the password window which caused this access denied issue.

Čamo
  • 3,863
  • 13
  • 62
  • 114
5

Interestingly, in a similar occasion using the HTTPS link worked for me.

ang3lkar
  • 109
  • 1
  • 8
  • It must be accepted answer by smart way, just go to submodule folder then clone https link -> WORK 100% – famfamfam May 14 '19 at 04:29
  • @famfamfam Absolutely not. If you need to do edits and be able to push your changes, you don't want to use the HTTPS protocol. – Alexis Wilke Jan 05 '21 at 16:41
1

Win10 + git bash terminal in VS Code. In my case, I was using git bash through VS Code. When using submodules, git pops up a window to enter pass phrase for the key. Bash through VSCode would't pop this up. With the windows Context menu item, "Git Bash Here" in the repo folder as shown below: Context menu Screen Grab

git submodule update

works splendidly.

0

Had the same problem with TortoiseGit / Windows subsystem for Linux / GitBash. The solution is to use authentication via an agent (key) instead of password.

For TortoiseGit:

  • run Pageant
  • add your key
  • enter password
  • TortoiseGit menu -> submodule update ...

(without pageant git clone it asks for password and works as intended, but git update fails with error)

For WS4L:

$ eval `ssh-agent -s`
$ chmod 600 /path/to/key
$ ssh-add /path/to/key

proceed with git submodule update

0

i had created a submodule in error by using git init in a parent folder AND in its subfolder. Just removed the .git folder and started over with git init in the correct parent folder.

0

In my case, the problem occurred when my project was placed in the system catalog (Program Files) despite the fact that the git clone was successful.

Also, this problem was not in the SSH key, this was also okay.

After moving it to folder C:\Users\username it works.

Try it, if you using Windows

kirkadev
  • 355
  • 4
  • 10
0
Cloning into '/data_hdd/xxx/3rdparty/deep_graph_libaray'...
xxxmodules/3rdparty/deep_graph_libaray: Permission denied
fatal: clone of 'https://xxx/deep_graph_libaray.git' into submodule path '/xxx/3rdparty/deep_graph_libaray' failed

I meet problem above, I sort it out. Here is my solution:

  1. docker run image -v 3rdparty/ mapping into container.
  2. git submodule add in container.

I think root user can do it.

Luke
  • 19
  • 3
0

Let's assume you have the proper access rights, the ssh key is working for normal repositories but not for submodules (as it was the case for me).

We added the submodules as relative path. As described here
So the .gitignore looks like this:

[submodule "example_json_client"]
    path = example_json_client
    url = ../example_json_client.git

This would imply that git use the same authentication method for the submodules as for the super repo. Note, if you changed from absolute url to relative, you might need to deinit and remove the submodule to take effect.

But! If your git config has a credential entry, it might fall back to HTTPS. To check it, execute

git config --global --list

Then look for an entry like (for me it is bitbucket, but there could be other provider, like github or gitlab, etc.),

credential.https:/bitbucket.mycompany.net.provider=bitbucket

Finally, if you remove that entry from the config, the submodule update with the proper authentication method should work.

zerocukor287
  • 555
  • 2
  • 8
  • 23
0

In my case I had checked out the code using https rather than ssh.

Solution was

  1. Generate an ssh key (https://docs.github.com/en/authentication/connecting-to-github-with-ssh/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent#adding-your-ssh-key-to-the-ssh-agent)
  2. Upload it to github by pasting content of your just generated key file into the form that appears when you press the "New Key" button on Github's Settings/"SSH and GPG keys" menu.

PS I found this solution when looking for why Github was always asking for my password. (https://docs.github.com/en/get-started/getting-started-with-git/why-is-git-always-asking-for-my-password)

joncaplan
  • 1
  • 1
-1

I had the same problem. I removed the entry from .gitmodules and executed git submodule init; git submodule update then I removed the entry from the file system and executed git submodule update --remote and it started downloading the submodule again.

Black
  • 18,150
  • 39
  • 158
  • 271