git拉代码或者git pull代码时候,每次都需要输入用户和密码,比较麻烦。
主角登场,轻松解决此问题:git-credential-store - 在磁盘上存储凭证的助手
只需要输入此命令
git config credential.helper store
再输入过一次账号密码,会自动保存在~/.git-credentials中,之后再也不会因为输入账号和密码烦恼,具体操作如第2章
第1章 git-credential-store描述
使用这个助手会将你的密码未加密地存储在磁盘上,只受文件系统权限的保护。如果这不是一个可接受的安全权衡,请尝试 git-credential-cache[1],或者找一个能与你的操作系统提供的安全存储整合的助手。 |
该命令在磁盘上无限期地存储凭证,供未来的 Git 程序使用。
你可能不想直接调用这个命令;它是作为 git 其他部分的凭证助手来使用的。
第2章 实例
git credential-store助手的意义在于减少你必须输入用户名或密码的次数。比如说:
$ git config credential.helper store
$ git push http://example.com/repo.git
Username: <输入您的用户名>
Password: <输入密码>
[几天后]
$ git push http://example.com/repo.git
[自动使用您的证书]
git config --global credential.helper store #全局
git config credential.helper store #单个项目
第3章 存储格式
.git-credentials
文件是以明文存储的(文件路径~/.git-credentials)
https://<username>:<password>@example.com
文件中不允许有其他类型的行(如空行或注释行),尽管有些行可能被默默地忽略了。不要用编辑器查看或编辑该文件。
当 Git 需要对某个特定的 URL 上下文进行认证时,credential-store 会将该上下文视为一种模式,与凭证文件中的每个条目进行匹配。 如果协议、主机名和用户名(如果我们已经有了)相匹配,那么密码就会返回给 Git。
第4章 清除git缓存中的用户名的密码
git credential-manager uninstall ##清除git缓存中的用户名的密码
参考文档: