我最近切换到将我的存储库同步到GitHub上的https://(由于防火墙问题),它每次都会要求输入密码。
有没有办法缓存凭据,而不是每次git推送时都进行身份验证?
我最近切换到将我的存储库同步到GitHub上的https://(由于防火墙问题),它每次都会要求输入密码。
有没有办法缓存凭据,而不是每次git推送时都进行身份验证?
当前回答
你可以使用
git config credential.helper store
当您下次使用pull或push输入密码时,它将以明文形式存储在文件.git凭据中(有点不安全,但只需将其放入受保护的文件夹中)。
如本页所述:
git凭证存储
其他回答
通常你有一个远程URL,像这样,
git remote -v
origin https://gitlab.com/username/Repo.git (fetch)
origin https://gitlab.com/username/Repo.git (push)
如果您想在使用git push时跳过用户名和密码,请尝试以下操作:
git remote set-url origin https://username:password@gitlab.com/username/Repo.git
我刚刚向origin添加了相同的URL(包括密码在内的用户详细信息)。
注意:如果用户名是电子邮件Id,则不起作用。
git remote -v
origin https://username:password@gitlab.com/username/Repo.git (fetch)
origin https://username:password@gitlab.com/username/Repo.git (push)
在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选择设备代码访问链接并输入输出中提供的代码
我并没有立即意识到我需要先下载助手!我在Atlassian的永久认证Git存储库中找到了credential.helper下载。
报价:
如果您想在OS X上使用带有凭据缓存的Git,请执行以下步骤:
下载二进制git凭证osxkeychain。
运行以下命令以确保二进制文件可执行:
chmod a+x git-credential-osxkeychain
将其放在/usr/local/bin目录中。
运行以下命令:
git config --global credential.helper osxkeychain
composer文档提到,您可以阻止它使用GitHub API,这样它的行为就像gitclone:
如果在GitHub存储库中将no-api键设置为true,它将像克隆任何其他Git存储库一样克隆存储库,而不是使用GitHub api。但与直接使用git驱动程序不同,composer仍然会尝试使用GitHub的zip文件。
因此,该部分将如下所示:
"repositories": [
{
"type": "vcs",
"no-api": true,
"url": "https://github.com/your/repo"
}
],
请记住,API存在是有原因的。因此,这应该是github.com上增加负载的最后手段。
您可以使用凭据助手。
git config --global credential.helper 'cache --timeout=x'
其中x是秒数。