我知道如何为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

但它们并没有起作用。


当前回答

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

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

其他回答

根据Michael Scharf的评论:

你可以省略密码,这样它就不会被记录在你的Bash历史文件中:

git clone https://username@github.com/username/repository.git

它将提示您输入密码。

或者,你可以使用:

git clone https://username:password@github.com/username/repository.git

我从GitHub存储库中找到了这种方法。

我用以下方法解决了这个问题:

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

生成访问令牌:

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

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

git config --global core.askpass

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

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

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