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

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


当前回答

根据rofrol在Linux Ubuntu上的评论,根据这个答案,下面是如何在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

其他一些发行版提供二进制文件,因此您不必构建它。

在OSX中,它通常“内置”了一个默认模块“osxkeychain”,因此您可以免费获得它。默认情况下,OS X内置和自制版本都有它。

其他回答

全局保存用户名和密码:

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

以前的答案对我来说都不管用。每次我想取东西或拉东西时,我都会得到以下答案:

输入密钥“/Users/myusername/.ssh/id_rsa”的密码:


适用于Mac

我可以通过以下方式阻止它询问我的密码:

通过运行:vi~/.ssh/config打开config添加了以下内容:UseKeychain yes保存并退出:按Esc,然后输入:wq!


对于Windows

我能够使用此Stack Exchange帖子中的信息使其发挥作用:如何避免每次推到Bitbucket时被询问密码

根据rofrol在Linux Ubuntu上的评论,根据这个答案,下面是如何在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

其他一些发行版提供二进制文件,因此您不必构建它。

在OSX中,它通常“内置”了一个默认模块“osxkeychain”,因此您可以免费获得它。默认情况下,OS X内置和自制版本都有它。

除了编辑~/.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用户保存配置参数。

如果您正在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中的凭据管理器二进制文件