$ git config --global user.name "John Doe"$ git config --global user.email johndoe@example.com
在GitBash中 输入 git config --global credential.helper store
执行完后去查看 %HOME%\.gitconfig 这个文件,发现多了一项:
[credential]
helper = store
1. 创建存储用户名密码的文件
在home文件夹 (Windows 直接 win + R 然后输入"%HOME%" 回车),新建名为 _netrc的文件, 里面的内容是:
machine github.com
login alex.gao@ucweb.com
password 102030
2. 新建名字是 .git-credentials的文件
(如果是 windows请注意, win 下不允许直接创建以 . 开头的文件,所以先创建一个文件名叫 git-credentials 的文件)
然后在gitbash / 命令行 cd 到%HOME%这个目录, 执行:
mv git-credentials .git-credentials
用记事本打开这文件输入,如果用户名中有@,那么使用%代替:
https://{username}:{password}@github.com
比如:
https://zhangsan%ucgit.com:123456@github.com
保存
3. 在GitBash中 输入 git config --global credential.helper store
执行完后去查看 %HOME%\.gitconfig 这个文件,发现多了一项:
[credential]
helper = store
三个文件如下
重新打开bash 或者使用tortoiseGit就不需要输入用户名密码了