我必须自动化克隆存储库并获取它的所有子模块。存储库子模块的 url 在 .gitmodules
中指定。如果我要使用默认设置,我会这样做
git clone --recursive https://username:password@url.git
问题是凭据未包含在 .gitmodules
文件中,当我克隆时系统会提示我输入这些凭据。我必须使用 HTTPS 而不是 SSH。
我尝试使用 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
但我在最后的更新步骤中收到输入凭据的提示。我检查过子模块 url 是否正确并且在 .git/config
文件中有正确的凭据。
最佳答案
看起来您正在尝试使用 git 凭据但没有任何运气。
选项 1
使用凭证助手添加凭证:
git config credential.https://example.com.username myusername
git config credential.helper "$helper $options"
检查您的 ~/.gitconfig 并验证是否添加了适当的条目。
进一步阅读: http://git-scm.com/docs/gitcredentials
选项 2
我会仔细检查您的 .git-credentials 文件的内容,如果不存在,则为子模块创建一个新条目。此文件由 git 凭证助手在内部使用。
http://git-scm.com/docs/git-credential-store
选项 3
Windows 中的简单解决方案是从模块文件中删除用户名和密码:
[submodule foo]
path = sub/foo
url = https://example.com/git/foo.git
并创建一个 ~/.netrc 文件。
machine example.com
login myusername
password areamandyingtotellsomeonehiscoolpassword
关于git - 克隆一个带有子模块 : override credentials 的 repo,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30040643/