我最近切换到将我的存储库同步到GitHub上的https://(由于防火墙问题),它每次都会要求输入密码。

有没有办法缓存凭据,而不是每次git推送时都进行身份验证?


当前回答

只需将登录凭据作为URL的一部分:

git remote rm origin
git remote add origin https://username:mypassword@github.com/path/to/repo.git

注意:我不建议使用这种方法,但如果你很匆忙,而其他方法都不奏效,你可以使用这种方法。

其他回答

我在MacOS上也遇到了这个问题,以下命令对我有效:

rm -rf  ~/.git-credentials 

这是一种强制方法,可以真正删除所有git凭据。下次我使用push命令时,瞧:系统会提示我输入用户名和密码(或令牌)。

双因素身份验证改变了用户对网站的身份验证方式,但Git仍然假设用户可以从内存中键入密码。

介绍git credential oauth:一个git凭据助手,可以使用oauth安全认证GitHub、GitLab、BitBucket和其他伪造文件。

没有更多密码!不再有个人访问令牌!不再有SSH密钥!第一次推送时,助手将打开浏览器窗口进行身份验证。缓存超时内的后续推送不需要交互。

从安装https://github.com/hickford/git-credential-oauth/releases/

配置方式:

git config --global --unset-all credential.helper
git config --global --add credential.helper "cache --timeout 7200" # two hours
git config --global --add credential.helper oauth

为了安全起见,最好使用凭据,但您可以使用缓存将其保存一段时间:

git config --global credential.helper cache
git config credential.helper 'cache --timeout=3600'

您的凭据将保存3600秒。

只需将登录凭据作为URL的一部分:

git remote rm origin
git remote add origin https://username:mypassword@github.com/path/to/repo.git

注意:我不建议使用这种方法,但如果你很匆忙,而其他方法都不奏效,你可以使用这种方法。

您可以使用凭据助手。

git config --global credential.helper 'cache --timeout=x'

其中x是秒数。