17

I'm trying to setup a git deploy setup, wherein I push my changes when ready to a git repo on a staging server, that then uses a post-recieve hook to deploy the code from the various branches to the appropriate web roots.

A problem I've encountered however is every time I run: git submodule update

I receive a password prompt, causing the deploy script to freeze up.

So far the things I've tried are:

  1. The submodule's hosted on a public repo and since I'm only ever trying to read from it, I don't see why it needs the password.
  2. That said, to try and work around this, I created new ssh keys for the staging server and when running outside of this one case are able to clone / fetch fine without any problems.
  3. I've also checked the .gitmodules and .git/config file to make sure the submodule is being pulled from the right place.
  4. When running the git submodule update and when presented with the password prompt just leaving the password empty and pressing enter seems to update things just fine, but the fact that I'm getting the prompt is whats messing up my hook script.

One thing to note is when setting up the repo on my staging server, I wasn't able to just clone the repo from my working instance due to firewall restrictions, so I instead cloned a copy locally then moved that newly cloned version to the server, and I've been able to push to it just fine.

Looking for any advice or tips I can get.

SS44
  • 837
  • 2
  • 10
  • 26

4 Answers4

23

Had the same issue. In my case it was caused by setting the submodule "url" to the https URL instead of the git@ URL.

levi
  • 23,693
  • 18
  • 59
  • 73
  • This worked for me. However, simply changing the url in `.submodules` and config files didn't work. I actually had to remove the [submodule complicated](https://stackoverflow.com/a/1260982/2311074) and add it again. – Adam Nov 18 '19 at 09:51
  • 7
    Same here, but I could avoid totally removing the submodules by running this command: `git submodule sync --recursive` from the main repo. This updated all submodule URLs – Johnny Fekete May 26 '21 at 09:49
  • If you don't want to sync with the git submodule, you can change the URL of your `.gitmodules` to `ssh@` and you also need to change the URL of the submodule to ssh under`.git/config` – felipekm Mar 30 '22 at 17:10
9

after change https://.. to git@... in .gitsubmodule run command

git submodule sync --recursive

user3319091
  • 101
  • 1
  • 2
1

If you can't replace the https:// with git@, you have the option to simply setup the password in your ~/.netrc file. Here the format:

machine githostname.com
  login yourgitusername
  password yourgitpassword
jav
  • 583
  • 5
  • 15
0

When supplying url's for submodules, you can either use a local file path or a url.

If you supply a url, try using something like: "git@bitbucket.org:myOrg/myRepo.git"

This allows system git to use the appropriate user to access the repo, if you're using the https://username@... then another user will have to supply the credentials needed to access the repo, or yourself if you haven't set up git with a user.