我使用Git已经有一段时间了,但不断的密码请求开始让我感到很烦。
我使用的是Mac OS X和GitHub,我按照GitHub的设置Git页面的指示设置Git和SSH密钥。
我还将github SSH密钥添加到了我的Mac OS X密钥链中,正如github的SSH密钥密码页面中提到的那样。我的公钥已在Git中注册。
然而,每次我尝试Git拉时,我都必须输入用户名和密码。除了SSH密钥之外,我是否需要为此设置其他东西?
我使用Git已经有一段时间了,但不断的密码请求开始让我感到很烦。
我使用的是Mac OS X和GitHub,我按照GitHub的设置Git页面的指示设置Git和SSH密钥。
我还将github SSH密钥添加到了我的Mac OS X密钥链中,正如github的SSH密钥密码页面中提到的那样。我的公钥已在Git中注册。
然而,每次我尝试Git拉时,我都必须输入用户名和密码。除了SSH密钥之外,我是否需要为此设置其他东西?
当前回答
如上所述,更改
https://github.com/username/repo.git
git://github.com/username/repo.git
to
ssh://git@github.com/username/repo.git
我自己将.git/config文件中的https更改为ssh,但仍然无法工作。然后我看到你必须将github.com更改为git@github.com.获取实际正确URL的一个好方法是转到您的项目页面并单击此项:
将HTTPS更改为SSH以获得正确的URL
然后将此URL添加到配置文件中。
其他回答
如果你想阻止Git总是要求你提供GitHub存储库的登录凭据,这很容易做到。
使用SSH而不是HTTPS
您可以使用SSH而不是HTTPS更新源远程“
git remote set-url origin git@github.com:username/your-repo.git
配置Git以存储密码和用户名
下面是如何让Git存储用户名和密码:
git config --global credential.helper store
接下来,保存会话的用户名和密码:
git config --global credential.helper cache
步骤1:检查当前配置
cat .git/config
您将获得:
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
ignorecase = true
precomposeunicode = true
[remote "origin"]
url = https://github.com/path_to_your_git.git
fetch = +refs/heads/*:refs/remotes/origin/*
[user]
name = your_username
email = your_email
[branch "master-staging"]
remote = origin
merge = refs/heads/master-staging
步骤2:删除远程源
git remote rm origin
步骤3:使用用户名和密码添加远程源
git remote add origin https://your_git_username:your_git_password@github.com/path_to_your_git.git
使用此命令:用适当的主机名替换github.com
git remote set-url origin git@github.com:user/repo.git
如果您使用https协议,Git将提示您输入密码。如果您使用ssh,它将使用您的私钥进行身份验证,而不是询问密码。
以下是解决此问题的方法:
git远程-v
这将显示来源的url。您将注意到此url中的https。(此处示例)
现在,您必须先删除这个,然后使用ssh添加url
git remote remove origin
git remote add origin git@github.com:PrestaShop/PrestaShop.git
Microsoft Stack解决方案(Windows和Azure DevOps)
首先打开.git/config文件,确保地址如下:
protocol://something@url
例如,Azure DevOps的.git/config:
[remote "origin"]
url = https://mystore@dev.azure.com/mystore/myproject/
fetch = +refs/heads/*:refs/remotes/origin/*
如果问题仍然存在,请打开Windows凭据管理器,单击名为Windows凭据的安全框并删除所有与git相关的凭据。
下次登录git时,它不会再消失。