我想在GitExtension中自动使用推拉,而不需要每次都在提示中输入我的用户和密码。
那么,我怎样才能在GIT中保存我的凭证?
运转
git config --global credential.helper store
然后
git pull
提供一个用户名和密码,然后这些细节就会被记住。凭证被存储在磁盘上的一个文件中,磁盘权限为"只是用户可读/可写",但仍为明文。
如果你以后想改变密码
git pull
将会失败,因为密码不正确,然后git会从~/.git-credentials
文件中删除违规的用户+密码,所以现在重新运行
git pull
来提供一个新的密码,这样就能像之前那样工作了。
你可以使用git config
来启用git中的凭证存储。
git config --global credential.helper store
运行此命令时,第一次从远程仓库拉取或推送时,会被问及用户名和密码。
此后,在与远程仓库的后续通信中,你不必再提供用户名和密码。
存储格式是一个.git-credentials
文件,以明文存储。
另外,你还可以使用git config credential.helper
的其他辅助工具,即内存缓存。
git config credential.helper cache <timeout>
它需要一个可选的`timeout参数'。 决定凭证在内存中保存多长时间。使用该辅助工具,凭证将永远不会接触到磁盘,并在指定的超时后被清除掉。默认值是 "900秒(15分钟)"。
警告 。如果你使用这种方法,你的git账户密码将以纯文本
格式保存在全局.gitconfig文件
中,例如在linux中它将是/home/[username]/.gitconfig
。
如果你不希望这样,可以用ssh钥匙
来代替你的账户。
在终端,输入以下内容。
# Set git to use the credential memory cache
git config --global credential.helper cache
默认情况下,Git 会缓存你的密码 15 分钟。
要改变默认的密码缓存超时,请输入以下内容。
# Set the cache to timeout after 1 hour (setting is in seconds)
git config --global credential.helper 'cache --timeout=3600'
来自 GitHub 帮助