Skip to main content
  1. About
  2. Stack Internal
The 2026 Annual Developer Survey is live— take the Survey today!

Return to Revisions

6 of 15
added 570 characters in body
Sam Saffron
  • reputation score 131822
  • 81 gold badges
  • 337 silver badges
  • 513 bronze badges

You must define:

  • environment variable %HOME%
  • put a _netrc file in %HOME%

If you are using Windows 7

run the cmd type this:

setx HOME %USERPROFILE%

and the %HOME% will be set to 'C:\Users\"username"'

then go to it and 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:

Using the latest version of msysgit on Windows 7, I did not need to set the HOME environment variable. The _netrc file alone did the trick.

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/
VonC
  • reputation score 1372765
  • 570 gold badges
  • 4812 silver badges
  • 5779 bronze badges

AltStyle によって変換されたページ (->オリジナル) /