我使用Git已经有一段时间了,但不断的密码请求开始让我感到很烦。

我使用的是Mac OS X和GitHub,我按照GitHub的设置Git页面的指示设置Git和SSH密钥。

我还将github SSH密钥添加到了我的Mac OS X密钥链中,正如github的SSH密钥密码页面中提到的那样。我的公钥已在Git中注册。

然而,每次我尝试Git拉时,我都必须输入用户名和密码。除了SSH密钥之外,我是否需要为此设置其他东西?


当前回答

步骤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上突然开始出现这种情况,这可能是由于GitHub最近在2018-02-22禁用了对不推荐的加密算法的支持,在这种情况下,解决方案只需下载并安装最新版本的完整Git for Windows或者仅使用Windows的Git凭据管理器。

如果每次尝试与GitHub交互时,Git都会提示您输入用户名和密码,那么您可能使用的是存储库的HTTPS克隆URL。

使用HTTPS远程URL有一些优点:它比SSH更容易设置,并且通常通过严格的防火墙和代理进行工作。然而,它也会在您每次拉动或推送存储库时提示您输入GitHub凭据。

您可以配置Git为您存储密码。对于Windows:

git config --global credential.helper wincred

面临着同样的问题。

请确保已正确设置远程原点:

$git remote add origin master "https://...git " 

如上所述,更改

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添加到配置文件中。

步骤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