本文介绍了Git的 - 如何使用.netrc文件在Windows上保存用户名和密码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 是否可以在Windows上使用.netrc文件,当我使用Git来克隆与HTTP和用户远程仓库 - 密码解决方案 更新的 2013年4月,混帐1.8.3 :您现在可以使用的加密的.netrc (使用GPG)。That script would allow you to use gpg-encrypted netrc files, avoiding the issue of having your credentials stored in a plain text file.To enable this credential helper:git config credential.helper '$shortname -f AUTHFILE1 -f AUTHFILE2'# and if you want lots of debugging info:git config credential.helper '$shortname -f AUTHFILE -d'#or to see the files opened and data found:git config credential.helper '$shortname -f AUTHFILE -v'See a full example at "Is there a way to skip password typing when using https:// github"Update late 2012, With git version 1.7.9+: This answer from Mark Longair details the credential cache mechanism which allows you to not store your password in plain text as shown below.(Original answer)You must define:environment variable %HOME%put a _netrc file in %HOME%If you are using Windows 7run the cmdtype this:setx HOME %USERPROFILE%and the %HOME% will be set to 'C:\Users\"username"'then go to itand make a file called '_netrc'Note: for Windows, you need a '_netrc' file, not a '.netrc'.Its content is quite standard (Replace the with your values):machine <hostname1>login <login1>password <password1>machine <hostname2>login <login2>password <password2>Luke mentions in the comments:This is indeed what I mentioned in "Trying to "install" github, .ssh dir not there":git-cmd.bat included in msysgit does set the %HOME% environment variable:@if not exist "%HOME%" @set HOME=%HOMEDRIVE%%HOMEPATH%@if not exist "%HOME%" @set HOME=%USERPROFILE%爱国者 believes in the comments that "it seems that it won't work for http protocol"However, I answered that netrc is used by curl, and works for http protocol, as shown in this example (look for 'netrc' in the page): . Also used with http protocol here: "_netrc/.netrc alternative to cURL".A common trap with with netrc support on Windows is that git will bypass using it if an origin https url specifies a user name.For example, if your .git/config file contains:[remote "origin"] fetch = +refs/heads/*:refs/remotes/origin/* url = https://[email protected]/p/my-project/Git will not resolve your credentials via _netrc, to fix this remove your username, like so:[remote "origin"] fetch = +refs/heads/*:refs/remotes/origin/* url = https://code.google.com/p/my-project/ 这篇关于Git的 - 如何使用.netrc文件在Windows上保存用户名和密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
06-28 04:13