git本地免密码和账号pull、push

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/CamilleZJ/article/details/55103149

说明:%HOME%,一般为C:\users\Administrator,也可以是你自己创建的系统用户名目录,反正都在C:\users\中

一.windows下:

需要创建一个.git-credentials文件,由于在Window中不允许直接创建以"."开头的文件,所以需要借助git bash进行,步骤如下:

1.打开git bash客户端,进入%HOME%目录(即C:\users\自己的电脑用户名,一般为C:\users\Administrator)


2.用touch创建文件 .git-credentials。


3.touch创建文件后用vim打开并编辑此文件,命令如下:

打开并编辑:vim .git-credentials(i-进入编辑模式)
编辑内容:https://{username}:{password}@github.com(登录账号,邮箱和密码)
保存编辑内容:按<ESC>键退出编辑模式,:wq  <回车>保存并退出
4.之后在如数

扫描二维码关注公众号,回复: 3282090 查看本文章
git config --global credential.helper store

打开%HOME%目录下的.gitconfig文件,会发现多了如下内容:

[credential]
helper = store

以上配置好后,关闭git bash重新打开,之后pull一个项目,首次还是要输入用户名及密码,之后pull成功后,再以后pull和push都不需要在输入用户名及密码了,此后打开新建的.git-credentials文件发现在https://{username}:{password}@github.com之上多了一条类似的文本。


二.Linux或者Mac下方法:

基本步骤和上面类似,就是linux下面可以直接创建.git-credential文件,命令如下:

创建文件,进入文件,输入内容:

cd ~
touch .git-credentials
vim .git-credentials
https://{username}:{password}@github.com

在终端下输入:

git config --global credential.helper store

打开~/.gitconfig文件,会发现多了一项:

[credential]
helper = store


本地Windows下还可以通过添加环境变量来配置,参考网址:http://www.cnblogs.com/ballwql/p/3462104.html

猜你喜欢

转载自blog.csdn.net/CamilleZJ/article/details/55103149