问题
I have to automate cloning a repository and fetching it's all submodules. The urls for repository submodules are specified at .gitmodules
. If I were to go with defaults I would just do
git clone --recursive https://username:password@url.git
The problem is credentials aren't included in .gitmodules
file and I am prompted for those when I clone. I have to use HTTPS rather then SSH.
I tried to submit the 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 prompted for credentials in the last update step. I've checked that the submodule url is correct and has proper credentials in .git/config
file.
回答1:
After editting the .gitmodules
file you need to apply changes using
git submodule sync
The next time you run git submodule update
the new url will be used.
回答2:
Looks like you are trying to use git credentials but not having any luck.
Option 1
Add credentials using the credential helper:
git config credential.https://example.com.username myusername
git config credential.helper "$helper $options"
Check your ~/.gitconfig and verify that the appropriate 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 it is not present. This file is used internally by the git credentials helper.
http://git-scm.com/docs/git-credential-store
Option 3
Easy solution in windows is to remove the username, password from 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
Kudos to Git submodule URL not including username?.
回答3:
If, like me, you are running CI and have access to a private token and already know the path to the submodule, you could use
git config credential.helper store
echo "https://LOGIN:${PAT}@github.com/path/to/submodule.git" > ~/.git-credentials
The next submodule update will not ask for credential.
Obviously, you'll want to clean this up once your done. In my case, I run in a docker container, so I don't have this concern.
来源:https://stackoverflow.com/questions/30040643/clone-a-repo-with-submodules-override-credentials