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

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


当前回答

除了编辑~/.gitconfig文件外,如果从命令行调用,还可以执行以下操作:

git config --local --edit

or

git config --global --edit

在默认文本编辑器中编辑git配置文件

您还可以使用命令行直接编辑git配置文件(无需编辑器)

git config --local user.name 'your username'
git config --local user.password 'your password'

or

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

请注意,始终使用单引号。如果您使用双引号,您的用户名和密码可能会使用一些会破坏密码的字符。

--local或--global表示为项目或OS用户保存配置参数。

其他回答

在这种情况下,您需要git凭据助手通过以下命令行告诉git记住您的GitHub密码和用户名:

git config --global credential.helper wincred

如果您使用的是使用SSH密钥的存储库,则需要SSH密钥进行身份验证。

您只需修改~/.git凭据

然后添加以下行:

git:https://<user>:<token/password>@gitlab.com

就是这样

您可以使用gitconfig在git中启用凭据存储。

git config --global credential.helper store

运行此命令时,当您第一次从远程存储库中拉入或推送时,会询问您的用户名和密码。

之后,对于与远程存储库的后续通信,您不必提供用户名和密码。

存储格式为.git凭据文件,以明文形式存储。

此外,您还可以为git-configcredential.helper使用其他助手,即内存缓存:

git config credential.helper 'cache --timeout=<timeout>'

它采用可选的超时参数,确定凭证将在内存中保留多长时间。使用帮助器,凭据将永远不会接触磁盘,并且在指定的超时后将被擦除。默认值为900秒(15分钟)。


警告:如果使用此方法,您的Git帐户密码将以明文格式保存在global.gitconfig文件中,例如在Linux中,它将是/home/[用户名]/.gitconfig。

如果您不希望这样做,请为您的帐户使用ssh密钥。

全局保存用户名和密码:

git config --global user.name "fname lname"
git config --global user.email "example@gmail.com"
git config --global user.password "secret"

获取特定设置,

git config --global --get user.name
git config --global --get user.email
git config --global --get user.password

正在获取所有Git设置:

git config --list --show-origin

如果您正在Windows上使用Git凭据管理器。。。

git-config-l应该显示:

credential.helper=manager

但是,如果没有提示您输入凭据,请执行以下步骤:

从“开始”菜单打开“控制面板”选择用户帐户在左侧菜单中选择管理凭据删除与Git或GitHub相关的任何凭据

如果您有代理并且Git服务器位于内部网络上,请确保您没有设置HTTP_PROXY、HTTPS_PROXY、NO_PROXY环境变量。

您还可以使用gitgui测试Git fetch/push/pull,gitgui链接到C:\Users\<username>\AppData\Local\Programs\Git\mingw64\libexec\Git-core中的凭据管理器二进制文件