Cloning repos with submodules: overriding credentials

I need to automate repository cloning and fetching all submodules. The URLs for the repository submodules are specified in .gitmodules . If I went with defaults, I would just do

 git clone --recursive https://username: password@url.git 

The problem is that the credentials are not included in the .gitmodules file, and I request them when cloning. I should use HTTPS, not SSH.

I tried to submit credentials using git config:

 git clone https://username: password@url.git my_repo cd my_repo git submodule init git config submodule.my_submodule.url "https://username: password@url /my_submodule.git" git submodule update 

but I get a credential request in the last step of the upgrade. I checked that the submodule URL is correct and has the appropriate credentials in the .git/config file.

+5
source share
2 answers

After editing the .gitmodules file .gitmodules you need to apply the changes using

 git submodule sync 

The next time you run git submodule update , the new URL will be used.

+7
source

It looks like you are trying to use git credentials but no luck.

Option 1

Add credentials using the credential assistant:

 git config credential.https://example.com.username myusername git config credential.helper "$helper $options" 

Check your ~ / .gitconfig file and make sure the corresponding entry is added.

Further reading: http://git-scm.com/docs/gitcredentials

Option 2

I would double check the contents of your .git-credentials file and make a new entry for the submodule if there is none. This file is used by the git internal credential helper.

http://git-scm.com/docs/git-credential-store

Option 3

A simple solution in Windows is to remove the username and password from the modules file:

 [submodule foo] path = sub/foo url = https://example.com/git/foo.git 

And create a ~ / .netrc file.

 machine example.com login myusername password areamandyingtotellsomeonehiscoolpassword 

Claims to Git URL of submodule not including username? .

+3
source

All Articles