首页 > 解决方案 > 如何在不要求每个子存储库的密码的情况下使用子模块克隆 git 存储库

问题描述

我最近将一个存储库放入 bitbucket。这个存储库有一些子模块

我正在编写一个初始化脚本。我想克隆主目录,然后他们拉出所有子目录。

 git clone https://bitbucket.org/#####/main.git elastic --recurse-submodules

这会提示我输入用户名和密码。

Username for 'https://bitbucket.org': myuser 
Password for 'https://myuser@bitbucket.org': 

他们再次向我询问每个子模块

Username for 'https://bitbucket.org':  
...

我的 .gitmodules 文件是这样的:

[submodule "api"]
     path = app/api/
     url = git@bitbucket.org/###/api.git
     branch = master
[submodule "front"]
     path = app/front
     url = git@bitbucket.org/###/front.git
     branch = master
[submodule "app/config"]
     path = app/config
     url = git@bitbucket.org/###/config.git
     branch = master

... some few more repositories

如何克隆主存储库,并且它们对所有子存储库使用相同的凭据?

我正在使用 AWS AMI Linux。

标签: gitgit-submodules

解决方案


设置 git 以使用凭证内存缓存解决了我的问题

git config --global credential.helper cache

这足以使用相同的用户/密码提取所有回购

如果我想一整天保持相同的缓存,我可以将时间设置为更长的时间跨度:

git config --global credential.helper 'cache --timeout=86400'

86400 秒 = 1 天;


推荐阅读