栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > .Net

git用户名和密码保存文件

.Net 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

git用户名和密码保存文件

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?

解决方案

You now can use an encrypted .netrc (with gpg).

A

That script would allow you to use gpg-encrypted netrc files, avoiding the issue of having your credentials stored in a plain text file.

Files with the .gpg extension will be decrypted by GPG before parsing.

Multiple -f arguments are OK. They are processed in order, and the first matching entry found is returned via the credential helper protocol.

When no -f option is given, .authinfo.gpg, .netrc.gpg, .authinfo, and .netrc files in your home directory are used in this order.

To enable this credential helper:

git config credential.helper '$shortname -f AUTHFILE1 -f AUTHFILE2'

(Note that Git will prepend "git-credential-" to the helper name and look for it

in the path.)

# 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'

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 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

login

password

machine

login

password

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://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/

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/979931.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号