Github密码缓存
· 阅读需 3 分钟
图片与正文无关
本文的知识点是关于 Git 和 Github 的,但我遇到这个问题是在使用 Octopress 写博客的过程中,每次写好一个要提交给 Github 时,总是问我要用户名和密码,所以我就想研究一下,是否可以记住账号密码,还别说真让我找到了,而且是 Github 网站帮助系统中的一小节,我打算翻译一下,毕竟是新学会了一个知识点。
PS:本文的知识点要求你的 Git 版本超过 1.7.10,系统是 Mac。
为了实现这个目的,你需要一个叫做 osxkeychain credential helper 的东东,不过有可能你已经安装了,如果你是使用的 homebrew 方式安装的 git,或者你的 git 是最新版本。
可以通过以下方式检查:
git credential-osxkeychain
# Test for the cred helper
# Usage: git credential-osxkeychain <get|store|erase>
如果你没有安装这个 helper,你需要手动安装一下:
git credential-osxkeychain
# Test for the cred helper
# git: 'credential-osxkeychain' is not a git command. See 'git --help'.
curl -s -O \
https://github-media-downloads.s3.amazonaws.com/osx/git-credential-osxkeychain
# Download the helper
$ chmod u+x git-credential-osxkeychain
# Fix the permissions on the file so it can be run
然后需要把这个脚本放到 Git 目录下:
sudo mv git-credential-osxkeychain \
"$(dirname $(which git))/git-credential-osxkeychain"
# Move the helper to the path where git is installed
# Password: [enter your password]
接着,需要告诉 Git 我们要用这个 helper, 简单的配置一下全局 Git 配置就行了
git config --global credential.helper osxkeychain
# Set git to use the osxkeychain credential helper
这样下次你提交代码时,会提示输入你账户和密码,并且 Mac 会弹窗问你是否授权使用钥匙链,授权后,以后提交代码就直接使用钥匙链里记录的密码,不会再提示输入了。
这样我写完一篇博客直接提交就可以了,So easy!
rake generate && rake deploy