我使用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密钥之外,我是否需要为此设置其他东西?
当前回答
我认为您可能有错误的Git存储库URL。
打开.git/config并找到[remote“origin”]部分。确保您使用的是SSH:
ssh://git@github.com/username/repo.git
如果单击克隆或下载并选择SSH,您可以在存储库的主页面中看到SSH URL。
而不是https或git:
https://github.com/username/repo.git
git://github.com/username/repo.git
现在,您可以只使用SSH密钥而不是用户名和密码进行验证。
如果Git抱怨已经添加了'origin',请打开.config文件,将[remote origin]后面的url=“…”部分编辑为url=ssh://github/username/repo.git
其他服务也是如此。确保地址如下:protocol://something@网址
例如,Azure DevOps的.git/config:
[remote "origin"]
url = https://mystore@dev.azure.com/mystore/myproject/
fetch = +refs/heads/*:refs/remotes/origin/*
其他回答
我认为您可能有错误的Git存储库URL。
打开.git/config并找到[remote“origin”]部分。确保您使用的是SSH:
ssh://git@github.com/username/repo.git
如果单击克隆或下载并选择SSH,您可以在存储库的主页面中看到SSH URL。
而不是https或git:
https://github.com/username/repo.git
git://github.com/username/repo.git
现在,您可以只使用SSH密钥而不是用户名和密码进行验证。
如果Git抱怨已经添加了'origin',请打开.config文件,将[remote origin]后面的url=“…”部分编辑为url=ssh://github/username/repo.git
其他服务也是如此。确保地址如下:protocol://something@网址
例如,Azure DevOps的.git/config:
[remote "origin"]
url = https://mystore@dev.azure.com/mystore/myproject/
fetch = +refs/heads/*:refs/remotes/origin/*
面临着同样的问题。
请确保已正确设置远程原点:
$git remote add origin master "https://...git "
正如其他人所说,您可以安装密码缓存助手。我主要只是想发布其他平台的链接,而不仅仅是Mac。我正在运行Linux服务器,这很有用:在Git中缓存GitHub密码
对于Mac:
git credential-osxkeychain
窗户:
git config --global credential.helper wincred
Linux:
git config --global credential.helper cache
git config --global credential.helper 'cache --timeout=3600'
# Set the cache to timeout after 1 hour (setting is in seconds)
步骤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
我有这个问题。回购要求我每次都输入凭证。我所有的其他经纪人都没有要求我出示证件。他们甚至被设置为在相同的帐户凭据下使用HTTPS跟踪GitLab,所以奇怪的是,除了一个,他们都工作得很好。
比较.git/config文件,我发现导致问题的URL中有两个关键差异:
确实要求提供凭据:
https://gitlab.com/myaccount/myproject
不要求提供凭据:
https://myaccount@gitlab.com/myaccount/myproject.git
因此,添加“myaccount@”和“.git”解决了我的问题。