我可以使用--recursive选项(对于子模块)为git clone添加用户名和密码吗?

Neo*_*yte 13 git git-submodules

我使用git通过https克隆一个repo因此:

git clone https://username:password@alocation/git/repo.git
Run Code Online (Sandbox Code Playgroud)

这很好,但它有大量的子目录要克隆,所以我使用该--recursive选项.

这里的问题是,对于顶级,它需要指定用户名和密码,但是对于每个子仓库,它再次询问详细信息,因此我得到以下内容:

C:>git clone --recursive https://username:password@alocation/git/repo.git
Cloning into repo...
remote: Counting objects: 15, done.
remote: Compressing objects: 100% (15/15), done.
remote: Total 15 (delta 8), reused 0 (delta 0)
Unpacking objects: 100% (15/15), done.
Submodule 'sub1' (https://alocation/git/repo.sub1) registered for path 'sub1'
Submodule 'sub2' (https://alocation/git/repo.sub2) registered for path 'sub2'
Submodule 'sub3' (https://alocation/git/repo.sub3) registered for path 'sub3'
Submodule 'sub4' (https://alocation/git/repo.sub4) registered for path 'sub4'
Cloning into sub1...
Username:
Password:
remote: Counting objects: 10, done.
remote: Compressing objects: 100% (8/8), done.
remote: Total 10 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (10/10), done.
Username:
..............................etc....
Run Code Online (Sandbox Code Playgroud)

我可以分别提供用户名和密码,所以我不必每次都输入.

明显的用例是针对像这样存在大量文件的深度子结构.为每个子参数输入相同的数据将变得繁琐且容易出错.

Von*_*onC 7

凭据应该对任何具有应该接受它们的地址的子模块有效.

可能失败的唯一情况是.gitmodules文件指向另一个repo,如Hunch Kod项目的案例214所示.

为了确保将这些凭据传递给每个"alocation"服务器的请求,您不需要在Git中调整任何内容,但这可能是ssh,curl或http代理设置.

我会排除ssh(alocation不会执行任何"username",但宁愿拥有专用的用户帐户).

如果您有代理,请检查您的http_proxy和https_proxy环境变量.

但是也可以尝试一下curl https://alocation/git/repo.git:
使用$HOME/.netrc(%HOME%\_netrc在Windows上),您可以指定预期的登录名/密码.

machine alocation
  login username
  password mypassowrd
Run Code Online (Sandbox Code Playgroud)

如果该工作https://alocation/git/repo.git(即没有要求您输入用户名和密码),它将适用于任何其他仓库(此处为子模块).