小编典典

有没有办法缓存 https 凭据以推送提交?

git

我最近切换到将我的存储库同步到 GitHub 上的 https:// on GitHub (due to firewall issues)),并且每次都要求输入密码。

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


阅读 249

收藏
2022-02-12

共1个答案

小编典典

自 Git 1.7.9(2012 年发布)以来,Git 中有一种简洁的机制可以避免在 HTTP / HTTPS 时一直输入密码,称为凭证助手

您可以只使用以下凭证助手之一:

git config --global credential.helper cache

credential.helper 缓存值告诉 Git将您的密码缓存在内存中特定的分钟数。默认值为 15 分钟,您可以设置更长的超时时间:

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

它将缓存设置为 1 小时,或者:

git config --global credential.helper "cache --timeout=86400"

1天。如果需要,您还可以永久存储您的凭据,请参阅下面的其他答案。

GitHub 的帮助还建议,如果您在 Mac OS X 上并使用Homebrew安装 Git,则可以使用本机 Mac OS X 密钥库:

git config --global credential.helper osxkeychain

对于 Windows,在 msysgit 中有一个名为Git Credential Manager for Windows或wincred 的助手。

git config --global credential.helper wincred # obsolete

使用适用于 Windows 2.7.3+ 的 Git(2016 年 3 月):

git config --global credential.helper manager

对于 Linux,您将使用 (in 2011) gnome-keyring(或其他密钥环实现,例如 KWallet)。

如今(2020 年),那将是(在 Linux 上)

Fedora

sudo dnf install git-credential-libsecret
git config --global credential.helper /usr/libexec/git-core/git-credential-libsecret

Ubuntu

sudo apt-get install libsecret-1-0 libsecret-1-dev
cd /usr/share/doc/git/contrib/credential/libsecret
sudo make
git config --global credential.helper /usr/share/doc/git/contrib/credential/libsecret/git-credential-libsecret
2022-02-12