我使用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密钥之外,我是否需要为此设置其他东西?
当前回答
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时,它不会再消失。
其他回答
orkoden关于在终端中使用带有Git的密钥链的回答不完整,并引发了错误。这是您必须执行的操作,以保存在钥匙链中的终端中输入的用户名和密码:
curl http://github-media-downloads.s3.amazonaws.com/osx/git-credential-osxkeychain -o git-credential-osxkeychain
sudo mv git-credential-osxkeychain /usr/local/bin
sudo chmod u+x /usr/local/bin/git-credential-osxkeychain
然后输入
git config --global credential.helper osxkeychain
如果你已经在curl之前完成了Git配置的部分,那没问题;它会奏效的。
使用以下命令增加超时时间,以便您可以暂时重新键入密码
git config --global credential.helper 'cache --timeout 3600'
我在Bitbucket和GitHub上使用了它,这两个都适用。你唯一需要做的就是3600秒。增加到你想要的程度。我把它改成了259200,大约30天。这样,我每隔30天左右重新输入一次密码。
步骤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
在windows机器中:安装GitHub CLI
choco install gh
然后运行命令:
gh auth login
并遵循说明
您也可以点击此链接:
https://cli.github.com/manual/gh_auth_login
当我升级到macOS v10.12(Sierra)时,我就遇到了这种情况。看起来SSH代理在升级时被清除了。
$ ssh-add -L
The agent has no identities.
只需运行ssh-add即可找到我的现有身份。我输入了密码,很高兴再去一次。