Is it possible to use a .netrc file on Windows when I’m using Git to clone a remote repository with HTTP and user – password?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Yes: You must:
%HOME%(pre-Git 2.0, no longer needed with Git 2.0+)_netrcfile in%HOME%If you are using Windows 7/10, in a
CMDsession, type:and the
%HOME%will be set to ‘C:\Users\"username"‘.Go that that folder (
cd %HOME%) and make a file called ‘_netrc‘Note: Again, for Windows, you need a ‘
_netrc‘ file, not a ‘.netrc‘ file.Its content is quite standard (Replace the
<examples>with your values):Luke mentions in the comments:
This is indeed what I mentioned in “Trying to “
install” github,.sshdir not there“:git-cmd.batincluded in msysgit does set the%HOME%environment variable:爱国者 believes in the comments that “it seems that it won’t work for http protocol”
However, I answered that
netrcis used bycurl, and works for HTTP protocol, as shown in this example (look for ‘netrc‘ in the page): . Also used with HTTP protocol here: “_netrc/.netrcalternative tocURL“.A common trap with with
netrcsupport on Windows is that git will bypass using it if an origin https url specifies a user name.For example, if your
.git/configfile contains:[remote "origin"] fetch = +refs/heads/*:refs/remotes/origin/* url = https://bob@code.google.com/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/Alternative solution: With git version 1.7.9+ (January 2012): This answer from Mark Longair details the credential cache mechanism which also allows you to not store your password in plain text as shown below.
With Git 1.8.3 (April 2013):
You now can use an encrypted .netrc (with
gpg).On Windows:
%HOME%/_netrc(_, not ‘.‘)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:
See a full example at “Is there a way to skip password typing when using
https:// github“With Git 2.18+ (June 2018), you now can customize the GPG program used to decrypt the encrypted
.netrcfile.See commit 786ef50, commit f07eeed (12 May 2018) by Luis Marsano (“).
(Merged by Junio C Hamano —
gitster— in commit 017b7c5, 30 May 2018)