git 使用子模块克隆存储库:覆盖凭据
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/30040643/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Clone a repo with submodules: override credentials
提问by sakovias
I have to automatecloning a repository and fetching it's all submodules. The urls for repository submodules are specified at .gitmodules
. If I were to go with defaults I would just do
我必须自动克隆存储库并获取它的所有子模块。存储库子模块的 url 在 中指定.gitmodules
。如果我要使用默认值,我会这样做
git clone --recursive https://username:[email protected]
The problem is credentials aren't included in .gitmodules
file and I am prompted for those when I clone. I have to use HTTPS rather then SSH.
问题是凭据未包含在.gitmodules
文件中,并且在我克隆时会提示我输入凭据。我必须使用 HTTPS 而不是 SSH。
I tried to submit the credentials using git config:
我尝试使用 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
but I get prompted for credentials in the last update step. I've checked that the submodule url is correct and has proper credentials in .git/config
file.
但在上次更新步骤中提示我输入凭据。我已经检查过子模块 url 是否正确并且在.git/config
文件中具有正确的凭据。
回答by Sébastien Dawans
After editting the .gitmodules
file you need to apply changes using
编辑.gitmodules
文件后,您需要使用
git submodule sync
The next time you run git submodule update
the new url will be used.
下次运行时git submodule update
将使用新的 url。
回答by jaypb
Looks like you are trying to use git credentials but not having any luck.
看起来您正在尝试使用 git 凭据,但没有任何运气。
Option 1
选项1
Add credentials using the credential helper:
使用凭证助手添加凭证:
git config credential.https://example.com.username myusername
git config credential.helper "$helper $options"
Check your ~/.gitconfigand verify that the appropriate entry is added.
检查您的~/.gitconfig并验证是否添加了适当的条目。
Further reading: http://git-scm.com/docs/gitcredentials
进一步阅读:http: //git-scm.com/docs/gitcredentials
Option 2
选项 2
I would double check the contents of your .git-credentials file and make a new entry for the submodule if it is not present. This file is used internally by the git credentials helper.
我会仔细检查您的 .git-credentials 文件的内容,如果它不存在,则为子模块创建一个新条目。该文件由 git 凭证帮助程序在内部使用。
http://git-scm.com/docs/git-credential-store
http://git-scm.com/docs/git-credential-store
Option 3
选项 3
Easy solution in windows is to remove the username, password from modules file:
Windows 中的简单解决方案是从模块文件中删除用户名和密码:
[submodule foo]
path = sub/foo
url = https://example.com/git/foo.git
And create a ~/.netrc file.
并创建一个 ~/.netrc 文件。
machine example.com
login myusername
password areamandyingtotellsomeonehiscoolpassword