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

sak*_*ias 7 git git-config git-clone git-submodules

我必须自动克隆存储库并获取它的所有子模块.存储库子模块的URL指定在.gitmodules.如果我要使用默认设置,我会这么做

git clone --recursive https://username:password@url.git
Run Code Online (Sandbox Code Playgroud)

问题是凭据不包含在.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
Run Code Online (Sandbox Code Playgroud)

但是在上次更新步骤中我被提示输入凭据.我已经检查过子模块url是否正确并且.git/config文件中有正确的凭据.

Séb*_*ans 8

编辑.gitmodules文件后,您需要使用应用更改

git submodule sync
Run Code Online (Sandbox Code Playgroud)

下次运行git submodule update新URL时将使用.


jay*_*ypb 6

看起来您正在尝试使用 git 凭据,但没有任何运气。

选项1

使用凭证助手添加凭证:

git config credential.https://example.com.username myusername
git config credential.helper "$helper $options"
Run Code Online (Sandbox Code Playgroud)

检查您的~/.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
Run Code Online (Sandbox Code Playgroud)

并创建一个 ~/.netrc 文件。

machine example.com
  login myusername
  password areamandyingtotellsomeonehiscoolpassword
Run Code Online (Sandbox Code Playgroud)

感谢Git 子模块 URL 不包括用户名?.