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

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


当前回答

克隆存储库repo后,可以编辑repo/.git/config并添加如下配置:

[user]
    name = you_name
    password = you_password
[credential]
    helper = store

这样就不会再次要求您输入用户名和密码。

其他回答

我从gitcredentials(7)手册页面得到了答案。就我而言,我的Windows安装中没有凭据缓存;我使用凭据存储。

使用凭据存储后,用户名/密码存储在[用户文件夹]/.git凭据文件中。要删除用户名/密码,只需删除文件的内容。

克隆存储库repo后,可以编辑repo/.git/config并添加如下配置:

[user]
    name = you_name
    password = you_password
[credential]
    helper = store

这样就不会再次要求您输入用户名和密码。

使用凭据存储。

对于OS X和Linux上的Git 2.11+,请使用Git内置的凭据存储:

git config --global credential.helper libsecret

对于Windows上的msysgit 1.7.9+:

git config --global credential.helper wincred

对于OS X上的Git 1.7.9+,请使用:

git config --global credential.helper osxkeychain

双因素身份验证改变了用户对网站的身份验证方式,但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

在Ubuntu上使用GitCredentialManager(GCM)在本地缓存凭据,在Ubuntu 20.04和18.04上进行了测试,但应该可以在其他Linux发行版上运行。

设置git凭据管理器:

curl -LO https://raw.githubusercontent.com/GitCredentialManager/git-credential-manager/main/src/linux/Packaging.Linux/install-from-source.sh
sh ./install-from-source.sh
git-credential-manager-core configure
git config --global credential.credentialStore cache
git config --global credential.cacheoptions "--timeout 72000"
sudo rm -rf git-credential-manager/
sudo rm install-from-source.sh

转到回购并运行git fetch选择设备代码访问链接并输入输出中提供的代码