【前言】
本地git环境采用Git-1.9.5-preview20150319与TortoiseGit-1.8.16.0-64搭建而成,但是每次进行克隆或提交操作都需要输入一次账号密码,这样不仅浪费了大量的时间而且降低了工作效率。在此背景下,通过搜索引擎找到了相关解决办法,现总结如下。
如下图,需要输入用户名密码。
【解决办法】
进入家目录下
C:\Users\"username"
其中username为你的电脑用户名。
然后创建一个"_netrc"文件。(Linux下是~/.netrc)
接着按以下内容格式编辑此文件即可。
machine <hostname1> #将"<hostname1>"替换为你的主机ip或域名,如github.com login <login1> #将"<login1>"替换为你的用户名 password <password1> #将"<password1>"替换为你的密码 machine <hostname2> #若你有多个git账号,按上面的格式添加即可 login <login2> password <password2>
然后,再次执行git clone,即可免密码克隆。
【后续】
这里_netrc文件是用明文存储的账号密码,安全性较低。可使用gpg4Win Lite
工具将加密netrc文件。
下载地址:http://files.gpg4win.org/Beta/
使用说明参考:http://stackoverflow.com/questions/5343068/is-there-a-way-to-skip-password-typing-when-using-https-github/18362082#18362082(Step-by-Step instructions for Windows
)
【参考】
http://stackoverflow.com/questions/6565357/git-push-requires-username-and-password
原文:http://xoyabc.blog.51cto.com/7401264/1726132