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

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

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

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


当前回答

面临着同样的问题。

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

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

其他回答

如果你想阻止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

在windows机器中:安装GitHub CLI

choco install gh

然后运行命令:

gh auth login

并遵循说明

您也可以点击此链接:

https://cli.github.com/manual/gh_auth_login

根据您的配置,有不同类型的身份验证。以下是一些:

git凭证osxkeychain。如果您的凭据无效,请通过以下方式删除它:git凭据osxkeychain擦除或:printf“protocol=https\nhost=github.com\n”| git凭据osxkeychain擦除因此Git不会再向您请求密钥链权限。然后再次配置。请参阅:在GitHub上从OS X密钥链更新凭据您的SSH RSA密钥。为此,您需要将SSH密钥与添加的密钥进行比较,通过SSH-add-L/sh-add-L检查您是否使用了正确的身份。您的HTTPS身份验证(如果您使用的是HTTPS而不是ssh协议)。使用~/.netrc(Windows上的%HOME%/_netrc)提供凭据,例如。机器存储1.mycompany.com登录myusername密码mypassword

了解更多:在堆栈溢出时与GitHub同步。

步骤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 Subsystem for Linux(WSL)上,这是我发现的唯一可行的解决方案:

eval `ssh-agent`; ssh-add ~/.ssh/id_rsa

这是ssh代理未在WSL中正确注册的问题。