git - 克隆一个带有子模块 : override credentials 的 repo

标签 git git-submodules git-clone git-config

我必须自动化克隆存储库并获取它的所有子模块。存储库子模块的 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 submodule URL not including username? .

关于git - 克隆一个带有子模块 : override credentials 的 repo,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30040643/

相关文章:

git - 建立Git存储库后Unity项目不再打开

带有空子模块文件夹的 GitHub zip 下载

git - 使用用户名和密码克隆 github 的私有(private)仓库

git:所有更改文件的列表,包括子模块中的文件

Git子模块绝对工作树路径配置

git - 如何做 "You' 需要使用有效的应用程序密码进行身份验证。”克隆 Bitbucket 存储库时?

Github 存储库不使用 gh cli 克隆

Git 对所有文件使用 --ours/--theirs 解决冲突

git - Mercurial 中的自定义修订属性?

git - 如何使用 'git rebase -i' 对分支中的所有更改进行 rebase ?