Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <blockquote> <p>Is it possible to use a <code>.netrc</code> file on Windows?</p> </blockquote> <p>Yes: You must:</p> <ul> <li>define environment variable <code>%HOME%</code> (pre-Git 2.0, no longer needed with Git 2.0+)</li> <li>put a <code>_netrc</code> file in <code>%HOME%</code></li> </ul> <p>If you are using Windows 7/10, in a <code>CMD</code> session, type:</p> <pre><code>setx HOME %USERPROFILE% </code></pre> <p>and the <code>%HOME%</code> will be set to '<code>C:\Users\"username"</code>'.<br> Go that that folder (<code>cd %HOME%</code>) and make a file called '<code>_netrc</code>'</p> <p>Note: Again, for Windows, you need a '<code>_netrc</code>' file, <em>not</em> a '<code>.netrc</code>' file.</p> <p>Its content is quite standard (Replace the <code>&lt;examples&gt;</code> with your values):</p> <pre><code>machine &lt;hostname1&gt; login &lt;login1&gt; password &lt;password1&gt; machine &lt;hostname2&gt; login &lt;login2&gt; password &lt;password2&gt; </code></pre> <hr> <p><a href="https://stackoverflow.com/users/197503/luke">Luke</a> mentions in the comments:</p> <blockquote> <p>Using the latest version of msysgit on Windows 7, I did not need to set the <code>HOME</code> environment variable. The <code>_netrc</code> file alone did the trick.</p> </blockquote> <p>This is indeed what I mentioned in "<a href="https://stackoverflow.com/questions/8514097/trying-to-install-github-ssh-dir-not-there/8531157#8531157">Trying to “<code>install</code>” github, <code>.ssh</code> dir not there</a>":<br> <a href="https://github.com/msysgit/msysgit/blob/master/git-cmd.bat" rel="nofollow noreferrer"><code>git-cmd.bat</code></a> included in msysgit does set the <code>%HOME%</code> environment variable:</p> <pre><code>@if not exist "%HOME%" @set HOME=%HOMEDRIVE%%HOMEPATH% @if not exist "%HOME%" @set HOME=%USERPROFILE% </code></pre> <hr> <p>爱国者 believes in the comments that "it seems that it won't work for http protocol"</p> <p>However, I answered that <code>netrc</code> is used by <code>curl</code>, and works for HTTP protocol, as shown in <a href="http://maymay.net/blog/2008/08/08/how-to-use-http-basic-authentication-with-git/" rel="nofollow noreferrer">this example</a> (look for '<code>netrc</code>' in the page): . Also used with HTTP protocol here: "<a href="https://stackoverflow.com/questions/5193643/netrc-netrc-alternative-to-curl"><code>_netrc</code>/<code>.netrc</code> alternative to <code>cURL</code></a>".</p> <hr> <p>A common trap with with <code>netrc</code> support on Windows is that git will bypass using it if an origin https url specifies a user name. </p> <p>For example, if your <code>.git/config</code> file contains: </p> <pre> [remote "origin"] fetch = +refs/heads/*:refs/remotes/origin/* url = https://bob@code.google.com/p/my-project/ </pre> <p>Git will not resolve your credentials via <code>_netrc</code>, to fix this remove your username, like so: </p> <pre> [remote "origin"] fetch = +refs/heads/*:refs/remotes/origin/* url = https://code.google.com/p/my-project/ </pre> <hr> <p>Alternative solution: With <strong>git version 1.7.9+</strong> (January 2012): <a href="https://stackoverflow.com/a/5343146/6309">This answer</a> from <a href="https://stackoverflow.com/users/223092/mark-longair">Mark Longair</a> details the <a href="http://git-scm.com/docs/git-credential-cache" rel="nofollow noreferrer"><strong>credential cache mechanism</strong></a> which <em>also</em> allows you to <em>not</em> store your password in plain text as shown below.</p> <hr> <p>With <a href="https://github.com/git/git/blob/master/Documentation/RelNotes/1.8.3.txt#L119-L120" rel="nofollow noreferrer">Git 1.8.3</a> (April 2013):</p> <p>You now can use an <strong>encrypted .netrc</strong> (with <code>gpg</code>).<br> On Windows: <code>%HOME%/_netrc</code> (<code>_</code>, not '<code>.</code>')</p> <blockquote> <p>A <strong><a href="https://github.com/git/git/blob/master/contrib/credential/netrc/git-credential-netrc" rel="nofollow noreferrer">new read-only credential helper</a></strong> (in <code>contrib/</code>) to interact with the <code>.netrc/.authinfo</code> files has been added.</p> </blockquote> <p>That script would allow you to <strong>use gpg-encrypted netrc files</strong>, avoiding the issue of having your credentials stored in a plain text file.</p> <blockquote> <p>Files with the <code>.gpg</code> extension will be decrypted by GPG before parsing.<br> Multiple <code>-f</code> arguments are OK. They are processed in order, and the first matching entry found is returned via the credential helper protocol.</p> <p>When no <code>-f</code> option is given, <code>.authinfo.gpg</code>, <code>.netrc.gpg</code>, <code>.authinfo</code>, and <code>.netrc</code> files in your home directory are used in this order.</p> </blockquote> <p>To enable this credential helper:</p> <pre><code>git config credential.helper '$shortname -f AUTHFILE1 -f AUTHFILE2' </code></pre> <blockquote> <p>(Note that Git will prepend "<code>git-credential-</code>" to the helper name and look for it in the path.)</p> </blockquote> <pre><code># 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' </code></pre> <p><strong>See a full example at "<a href="https://stackoverflow.com/a/18362082/6309">Is there a way to skip password typing when using <code>https:// github</code></a>"</strong></p> <hr> <p>With Git 2.18+ (June 2018), you now can customize the GPG program used to decrypt the encrypted <code>.netrc</code> file.</p> <p>See <a href="https://github.com/git/git/commit/786ef50a23cbd0e93d1e41982cfaba76801ed885" rel="nofollow noreferrer">commit 786ef50</a>, <a href="https://github.com/git/git/commit/f07eeed123b8880b1723b1ea9d6d6f41cfb34532" rel="nofollow noreferrer">commit f07eeed</a> (12 May 2018) by <a href="https://github.com/" rel="nofollow noreferrer">Luis Marsano (``)</a>.<br> <sup>(Merged by <a href="https://github.com/gitster" rel="nofollow noreferrer">Junio C Hamano -- <code>gitster</code> --</a> in <a href="https://github.com/git/git/commit/017b7c52fc00897c72f6c4808ded43c4c5f9c5b8" rel="nofollow noreferrer">commit 017b7c5</a>, 30 May 2018)</sup> </p> <blockquote> <h2><code>git-credential-netrc</code>: accept <code>gpg</code> option</h2> <p><code>git-credential-netrc</code> was hardcoded to decrypt with '<code>gpg</code>' regardless of the gpg.program option.<br> This is a problem on distributions like Debian that call modern GnuPG something else, like '<code>gpg2</code>'</p> </blockquote>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload