我知道如何为HTTPS请求提供用户名和密码,就像这样:

git clone https://username:password@remote

但是我想知道如何像这样为遥控器提供用户名和密码:

git clone git@remote.git

我是这样尝试的:

git clone username:password@git@remote.git
git clone git@username:password@remote.git
git clone git@remote.git@username:password

但它们并没有起作用。


当前回答

git config --global core.askpass

在克隆之前先运行这个,应该是固定的!

其他回答

如果你有凭据存储在任何类型的凭据帮助中,但没有将凭据帮助配置为全局激活,你可以像这样克隆:

git clone https://git.example.com/ns/repo.git --config=credential.helper=store

这将在克隆之前在本地设置凭据帮助配置(仅针对新的回购)。

要克隆存储库,首先应该生成一个访问令牌(您不能再使用登录密码),然后使用这个生成的令牌克隆存储库。

生成访问令牌:

github: 设置>开发人员设置>个人访问令牌>生成新的令牌

bitbucket都: 个人设置>应用密码>创建应用密码

克隆存储库:

github:

$ git clone https://YOUR-USERNAME:GENERATED-TOKEN@github.com/YOUR-USERNAME/YOUR-REPOSITORY

bitbucket都:

git clone https://YOUR-USERNAME@bitbucket.org/YOUR-REPOSITORY

它将提示您输入已生成的令牌。

如果这些参数正在产生问题,请使用ur的特殊情况替换它们:

 !   #   $   &   '   (   )   *   +   ,   /   :   ;   =   ?   @   [   ]

%21 %23 %24 %26 %27 %28 %29 %2A %2B %2C %2F %3A %3B %3D %3F %40 %5B %5D

举个例子

实际URL: https://usern@me:p@ssword@git/reponame.git

使用的解决方案URL: https://usern%40me:p%40ssword@git/reponame.git

在Windows上,当git克隆时,以下步骤应该重新触发GitHub登录窗口:

在开始菜单中搜索“凭据管理器” 选择“Windows凭证” 删除所有与Git或GitHub相关的凭证

如果您正在使用http/https,并且希望完全自动化该过程,而不需要任何用户输入或任何用户提示(例如:在CI/CD管道中),您可以使用以下方法利用git凭据.helper

GIT_CREDS_PATH="/my/random/path/to/a/git/creds/file"
# Or you may choose to not specify GIT_CREDS_PATH at all.
# See https://git-scm.com/docs/git-credential-store#FILES for the defaults used

git config --global credential.helper "store --file ${GIT_CREDS_PATH}"
echo "https://alice:${ALICE_GITHUB_PASSWORD}@github.com" > ${GIT_CREDS_PATH}

在这里你可以选择设置ALICE_GITHUB_PASSWORD环境变量从以前的shell命令或从管道配置等。

记住,基于“存储”的git- credentials -helper以明文形式存储密码和值。因此,请确保您的令牌/密码的权限非常有限。


现在只需使用https://alice@github.com/my_repo.git无论你的自动系统需要获取回购-它将使用凭据alice在github.com存储由git-credential-helper。