Fatal Error when updating submodule using GIT
Asked Answered
E

8

60

I am trying to update the submodules of this git repositary but I keep getting a fatal errors:

[root@iptlock ProdigyView]# git submodule update --recursive
Cloning into core...
Permission denied (publickey).
fatal: The remote end hung up unexpectedly
Clone of '[email protected]:ProdigyView/ProdigyView-Core.git' into submodule path 'core' failed

Or this way

[root@iptlock root]# git clone --recursive https://github.com/ProdigyView/ProdigyView.git
Cloning into ProdigyView...
remote: Counting objects: 438, done.
remote: Compressing objects: 100% (275/275), done.
remote: Total 438 (delta 172), reused 394 (delta 128)
Receiving objects: 100% (438/438), 8.03 MiB | 5.19 MiB/s, done.
Resolving deltas: 100% (172/172), done.
Submodule 'core' ([email protected]:ProdigyView/ProdigyView-Core.git) registered for path 'core'
Cloning into core...
Permission denied (publickey).
fatal: The remote end hung up unexpectedly
Clone of '[email protected]:ProdigyView/ProdigyView-Core.git' into submodule path 'core' failed

Any ideas of why this is happening withthe submodule? The repo is this one:

https://github.com/ProdigyView/ProdigyView

(The submodule is able to be cloned if I do not try to clone it as a submodule.)

Erikerika answered 19/11, 2011 at 20:33 Comment(1)
If it may help, adding the public key in github did the job for me.Intrepid
E
-10

Figured it out. The path in the .gitmodule files could not download the submodule.

Erikerika answered 19/11, 2011 at 21:0 Comment(8)
I'm having this same issue. Could you elaborate on what was wrong and how you fixed it?Fetlock
This is how I have solved this problem: In the .gitmodules file and .git/config file, you will see url path for the submodule you want to update. If it is like git@github... change it to a valid url: git//github.com/.... it will solve the problem.Enounce
This answer is terribly unclear. Khune Vu's suggestion did not resolve the issue either.Clairvoyant
Sorry, in your clone directory open up open the file .gitsubmodule. In there you will see that the submodules have paths that are related to the repo in which they are cloned from. Make sure the url that it is cloning from is correct. BTW, the .gitsubmodule is invisible, do an ls -l a from the root to to see it.Erikerika
After modifying the path in both places, I kept getting the same errors. I had to delete the folder of the submodule. Do git submodule sync and then git submodule update --initReamonn
Arnaldo, thanks for this, this solved the problem I ran into as well.Tishtisha
@DevinDixon edit your answer to actually explain what you changed.Kabul
This is such a terrible answer. Not only is the file called .gitmodules not .gitmodule, but all you've done is paraphrased your original question, and given no explanation to help anyone else. Thankfully there is a great answer which Daniël W. Crompton posted, and I encourage you to change the accepted answer to that one @DevinDixon . Meanwhile, I will propose an edit to yoursTuition
J
99

The issue is that git can't find the public key needed to download the repo from your server, the solution is to use the public url.

In the file .gitmodule you will find the following entry:

[submodule "example"]
    path = example
    url = [email protected]:webhat/example.git

The URL need to be changed to the public URL for the module:

[submodule "example"]
    path = example
    url = https://github.com/webhat/example.git

As you can see the prefix git@ has been changed to https:// and the infix : becomes /

EDIT: In your own repository you might need to use git:// rather than https://

The previous answer was unclear to me, so I added this.

EDIT 2: If you find you need to run git submodule sync or need to edit .git/config to get this to work, you have likely set up remotes for the submodules.

Jobholder answered 11/2, 2013 at 7:56 Comment(5)
I ran into the same problem today and Github seems to offer public cloning only via HTTPS nowadasy. The URL in your example would have been https://github.com/webhat/example.git thenVolcanism
Repeat the procedure in .git/configSlumberous
@Slumberous I didn't have an issue with .git/config after updating.Sophrosyne
This worked for me, but had to run: git submodule sync before running the git submodule update --init --recursivePrecontract
Don't forget to: git submodule sync git submodule init git submodule updateArbalest
S
52

If it can help some people:

I update my .gitmodules

[submodule "example"]
  path = example
  url = https://github.com/webhat/example.git

Then I update my .git/config too

[submodule "example"]
  url = https://github.com/webhat/example.git

Like some of you said it before (and I thank you).

Then I update my .git/modules/example/config

[remote "origin"]
  fetch = [...]
  url = https://github.com/webhat/example.git

And to finish I do

git submodule sync
git submodule init
git submodule update
Sounding answered 13/5, 2014 at 14:25 Comment(1)
The last 3 lines (sync, init, update) helped me when I cloned a project with submodules via Sourcetree. Sourcetree successfully had configured .gitmodules but I was not able to checkout to submodule branches until I synched, initialized and updated. Then I closed and opened Sourcetree and everything was working fine.Batista
L
7

You can manually pass in the key in Build --> "Execute shell" section of jenkins job :

ssh-agent bash -c 'ssh-add {path_to_private_key}; git submodule update --init --recursive'

Example:

ssh-agent bash -c 'ssh-add /var/lib/jenkins/.ssh/jenkins_rsa; git submodule update --init --recursive'

Legerdemain answered 13/9, 2015 at 21:35 Comment(2)
This is actually useful. Even on Windows machine trying to just git submodule update gives you access denied, because no key is actually used.Intercept
That was the fix that helped me, kinda. I thought that maybe that's the cause and run the git commands in git bash instead of windows cmd and it asked to the password in the modal, which cmd never did. Looks like another windows bug..Perilous
T
6

This is happened that many times for me that I put a function in my .bash_profile (works on BSD sed / GNU / Mac):

gitfix () {
if [ -f "./.gitmodules" ] ; then
    sed -E -i.bak -e "s/(url *= *)(.*:)(.*)/\1https:\/\/github.com\/\3/g" .gitmodules \
    git submodule sync
    git submodule update --init --recursive
fi
}

A one liner:

sed -E -i.bak -e "s/(url *= *)(.*:)(.*)/\1https:\/\/github.com\/\3/g" .gitmodules ; git submodule sync ; git submodule update --init --recursive

vim search/replace:

%s/\(url\s*=\s*\)\(.*:\)\(.*\)/\1https:\/\/github.com\/\3/

Underlying solution based on Daniël 's answer

Tuition answered 2/8, 2017 at 4:25 Comment(0)
F
5

The following steps will fix the problem.

  1. Delete the folder of the submodule on your local.
  2. Do git submodule sync
  3. then git submodule update --init

Hope this helps.

Fredia answered 24/8, 2015 at 22:48 Comment(0)
H
3

I had this same issue. However, in my situation, the team wanted to use the SSH access from the .gitmodules, so modifying the URL to use http:// was not an option.

Ultimately, my issue was having an incorrect ~/.ssh/config file. The config file had some erroneous settings, so I was actually trying to access the incorrect server every time I'd really want to access [email protected]. I found this out by executing the following command:

ssh -vT [email protected]

The third line or so should say this:

debug1: Connection to github.com [<ip address>] port <port num>

If you aren't attempting to connect to github.com, then your config file is pointing you off course.

Turns out I didn't need any of the stuff in my config file anyway, so I was safe to delete it. If you want to maintain a config file, here is a good article on that:

http://nerderati.com/2011/03/17/simplify-your-life-with-an-ssh-config-file/

Also, these GitHub docs really helped me debug my issue:

https://help.github.com/articles/error-permission-denied-publickey

https://help.github.com/articles/what-ip-addresses-does-github-use-that-i-should-whitelist

Hygrostat answered 4/8, 2014 at 17:25 Comment(0)
V
3

Adding new answer instead of edit for greater visibility to anyone experience the same problem I was...

I had the exact opposite. Private Bitbucket repo & submodule for work. Always got this error...

fatal: repository 'http://bitbucket.org/companyname/submodule-repo-name.git' does not exist
fatal: clone of 'http://bitbucket.org/companyname/submodule-repo-name.git' into submodule path 
'/Users/me/path/to/repo-using-submodule/folder' failed
Failed to clone 'submodule/folder'. Retry scheduled
fatal: repository 'http://bitbucket.org/companyname/submodule-repo-name.git' does not exist
fatal: clone of 'http://bitbucket.org/companyname/submodule-repo-name.git' into submodule path 
'/Users/me/path/to/repo-using-submodule/folder' failed
Failed to clone 'submodule/folder' a second time, aborting

I had to manually go into my .git/config file and update this:

[submodule "submodule-name"]
url = https://bitbucket.org/companyname/submodule-repo.git

with this:

[submodule "submodule-name"]
url = [email protected]:companyname/submodule-repo.git

Not sure how to set this up so me and all my coworkers can use the submodule without tweaking, but got me past my several month long struggle with this.

Varnish answered 15/5, 2020 at 19:20 Comment(0)
E
-10

Figured it out. The path in the .gitmodule files could not download the submodule.

Erikerika answered 19/11, 2011 at 21:0 Comment(8)
I'm having this same issue. Could you elaborate on what was wrong and how you fixed it?Fetlock
This is how I have solved this problem: In the .gitmodules file and .git/config file, you will see url path for the submodule you want to update. If it is like git@github... change it to a valid url: git//github.com/.... it will solve the problem.Enounce
This answer is terribly unclear. Khune Vu's suggestion did not resolve the issue either.Clairvoyant
Sorry, in your clone directory open up open the file .gitsubmodule. In there you will see that the submodules have paths that are related to the repo in which they are cloned from. Make sure the url that it is cloning from is correct. BTW, the .gitsubmodule is invisible, do an ls -l a from the root to to see it.Erikerika
After modifying the path in both places, I kept getting the same errors. I had to delete the folder of the submodule. Do git submodule sync and then git submodule update --initReamonn
Arnaldo, thanks for this, this solved the problem I ran into as well.Tishtisha
@DevinDixon edit your answer to actually explain what you changed.Kabul
This is such a terrible answer. Not only is the file called .gitmodules not .gitmodule, but all you've done is paraphrased your original question, and given no explanation to help anyone else. Thankfully there is a great answer which Daniël W. Crompton posted, and I encourage you to change the accepted answer to that one @DevinDixon . Meanwhile, I will propose an edit to yoursTuition

© 2022 - 2024 — McMap. All rights reserved.