我可以添加用户名和名称吗?使用 --recursive 选项(对于子模块)的 git clone 密码?
我正在使用 git 通过 https 克隆存储库:
git clone https://username:password@alocation/git/repo.git
这很好,但它也有大量的子存储库可供克隆,因此我使用 --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....
我可以提供用户名和密码吗?密码分开,这样我就不必每次都输入。
明显的用例是像这样有大量文件的深层子存储库结构。为每个子存储库输入相同的数据将会变得乏味且繁琐。容易出错。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
凭据对于任何具有接受它们的地址的子模块都应该有效。
唯一可能失败的情况是 .gitmodules 文件指向另一个存储库,如 Hunch Kod 项目的案例 214。
为了确保这些凭据传递到“分配”服务器的每个请求,您不需要在 Git 中调整任何内容,但这可能是 ssh、curl 或 http 代理设置。
我会排除 ssh (分配不会以“用户名”执行任何操作,而是希望有一个专用的用户帐户)。
如果您有代理,请检查您的 http_proxy 和 https_proxy 环境变量。
但也可以尝试一个简单的
curl https://alocation/git/repo.git
:使用
$HOME/.netrc
(Windows 上为%HOME%\_netrc
),您可以指定所需的登录名/密码。如果这适用于
https://alocation/git/repo.git
(即不要求您提供用户名和密码),它也适用于任何其他存储库(此处为子模块)。The credentials should be valid for any submodules with an address supposed to accept them.
One only case where it could fail is when the .gitmodules file points to another repo, as illustrated by the case 214 of the Hunch Kod project.
To make sure those credentials are passed to every request to 'alocation' server, you don't need to tweak anything in Git, but this is probably a ssh, curl or http proxy settings.
I would rule out ssh (alocation wouldn't execute anything as 'username' but would rather have a dedicated user account).
Check your http_proxy and https_proxy environment variable if you have a proxy.
But try also a simple
curl https://alocation/git/repo.git
:With a
$HOME/.netrc
(%HOME%\_netrc
on Windows), you can specify the login/password expected.If that work for
https://alocation/git/repo.git
(i.e. without asking you for a username and password), it will work for any other repo( here submodules).