我曾经切换过一次 github 账号, 似乎还更改过一次 github 账号的密码, 然后呢?
然后就是每次向 github 提交代码时都要输入用户名密码(猜测是由于上述原因导致),
每次都是啊, 这也忒麻烦了, 于是就想办法解决这个问题, 经过一番查找, 终于找到一个解决办法, 分享之, 与君共勉 !!
==============
解决方案:
在你的用户目录下新建一个文本文件, 名曰. git-credentials
用户目录:
windows: C:/Users/username
mac os x: /Users/username
linux: /home/username
在上一步创建的文件中输入一下内容:
https:{username}:{password}@github.com mailto:%7Bpassword%7D@github.com
当然上述 {username} 和{password}要换成你的 github 的账号名和密码
修改 git 配置
执行命令 git config --global credential.helper store
上述命令会在~/.gitconfig 文件末尾添加如下配置:
- [credential]
- helper = store
经过上述三步配置之后, 你 push 代码到 github 时, 便无需再输入用户名密码了~~
=================
续集......
后来发现, 不用上面三步这么麻烦, 简化流程如下:
在命令行输入命令:
git config --global credential.helper store
? 这一步会在用户目录下的. gitconfig 文件最后添加:
- [credential]
- helper = store
现在 push 你的代码 (git push), 这时会让你输入用户名密码, 这一步输入的用户名密码会被记住, 下次再 push 代码时就不用输入用户名密码啦!
? 这一步会在用户目录下生成文件. git-credential 记录用户名密码的信息.
? git config --global 命令实际上在操作用户目录下的. gitconfig 文件, 我们 cat 一下此文件(cat .gitconfig), 其内容如下:
- [user]
- name = alice
- email = mailto:alice@aol.com
- [push]
- default = simple
- [credential]
- helper = store
git config --global user.email "alice@aol.com mailto:%22alice@aol.com" 操作的就是上面的 email
git config --global push.default matching 操作的就是上面的 push 段中的 default 字段
git config --global credential.helper store 操作的就是上面最后一行的值
原文信息
作者: 元亨利贞 o
链接: https://www.jianshu.com/p/81ae6e77ff47
來源: 简书
来源: http://www.bubuko.com/infodetail-2581067.html