当我们换了新电脑进行开发项目的时候,总会面临一个问题,每次提交代码都让你输一遍用户名和密码,简直不能再麻烦了,尤其在你急需解决问题的时候,真是有种想把电脑摁在地上摩擦的冲动!
解决方案:
在终端输入如下命令:
git config --global credential.helper store
1.这一步会在用户目录下的.gitconfig
文件最后添加:
[credential]
helper = store
2.现在你提交代码时输入用户名密码, 此时输入的用户名密码会被记住, 下次再push代码时就不用输入用户名密码了。
这一步会在用户目录下生成文件.git-credential
记录用户名密码的信息
git config --global
命令实际上在操作用户目录下的.gitconfig
文件, 我们cat
一下此文件(cat .gitconfig
), 其内容如下:
[user]
name = abc
email = abc@123.com
[push]
default = simple
[credential]
helper = store
git config --global user.email "abc@123.com"
操作的就是上面的email
git config --global push.default matching
操作的就是上面的push段中的default字段
git config --global credential.helper store
操作的就是上面最后一行的值