git 使用子模块克隆存储库:覆盖凭据

svmlkihl  于 9个月前  发布在  Git
关注(0)|答案(3)|浏览(150)

我必须 * 自动化 * 克隆存储库并获取其所有子模块。存储库子模块的URL被指定为.gitmodules。如果我使用默认值,我只会这样做

git clone --recursive https://username:[email protected]

字符串
问题是.gitmodules文件中不包含凭据,当我克隆时会提示我输入这些凭据。我必须使用HTTPS而不是SSH。
我尝试使用git config提交凭据:

git clone https://username:[email protected] 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文件中有适当的凭据。

juud5qan

juud5qan1#

如果像我一样,您正在运行CI,并且可以访问私有令牌,并且已经知道子模块的路径,则可以使用

git config credential.helper store
echo "https://LOGIN:${PAT}@github.com/path/to/submodule.git" > ~/.git-credentials

字符串
下一次子模块更新将不会要求凭据。
很明显,你会想在完成后清理它。在我的例子中,我运行在一个docker容器中,所以我没有这个问题。

i2loujxw

i2loujxw2#

看起来你正在尝试使用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 credentials helper内部使用。
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


X1 E2 F1 X的荣誉。

ulydmbyx

ulydmbyx3#

编辑.gitmodules文件后,需要使用

git submodule sync

字符串
下次运行git submodule update时,将使用新的url。

相关问题