我想在GitExtensions、Sourcetree或任何其他GitGUI中自动使用推拉,每次都不需要在提示中输入用户名和密码。

那么我如何在Git中保存我的凭据?


当前回答

注意:此方法以明文形式将凭据保存在电脑磁盘上。计算机上的每个人都可以访问它,例如恶意NPM模块。

Run

git config --global credential.helper store

then

git pull

提供用户名和密码,这些详细信息稍后将被记住。凭证存储在磁盘上的文件中,磁盘权限为“仅用户可读/可写”,但仍为明文。

如果以后要更改密码

git pull

将失败,因为密码不正确,git然后从~/.git凭据文件中删除有问题的用户+密码,因此现在重新运行

git pull

以提供一个新密码,以便与之前一样工作。

其他回答

只需使用

git config --global credential.helper store

然后做数字拉动。它将要求输入用户名和密码。从现在起,它将不会提供任何用户名和密码提示。它将存储详细信息。

git config --global user.name "your username"
git config --global user.password "your password"

检查

git config --list

对于Windows用户,请查看.gitconfig文件并检查为凭据助手配置了什么。如果您有以下内容。。。

[凭证“helperselector”]selected=绞车

您将在Windows凭据管理器中找到凭据。

您可以在那里编辑凭证。

注意:Wincred已被弃用,请参阅。。。

https://github.com/Microsoft/Git-Credential-Manager-for-Windows#notice-该项目不再处于警告状态

因此,您可能需要重新配置Git以使用内置的Git凭据管理器。。。

git config --global credential.helper manager

您可以使用git凭据存储将未加密的密码存储在磁盘上,仅受文件系统权限的保护。

实例

git config credential.helper store
git push http://example.com/repo.git

Username: <type your username>
Password: <type your password>

[Several days later]

git push http://example.com/repo.git

[Your credentials are used automatically]

您可以检查存储在文件~/.git凭据中的凭据。

有关更多信息,请访问git credential store-Helper将凭据存储在磁盘上。

推荐的安全方法:SSH

创建SSH GitHub密钥。转到github.com→ 设置→ SSH和GPG密钥→ 新SSH密钥。现在将您的私钥保存到计算机。

然后,如果私钥保存为~/.ssh/目录中的id_rsa,我们将其添加为身份验证:

ssh-add -K ~/.ssh/id_rsa

更安全的方法:缓存

我们可以使用git凭据缓存在一段时间内缓存用户名和密码。只需在CLI(终端或命令提示符)中输入以下内容:

git config --global credential.helper cache

您还可以按如下方式设置超时时间(以秒为单位):

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