在Visual Studio中为Microsoft Git Provider设置代理 [英] Set proxy for Microsoft Git Provider in Visual Studio

查看:160
本文介绍了在Visual Studio中为Microsoft Git Provider设置代理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须使用http代理连接到Git服务器。我可以通过Git Bash设置它,并通过以下命令使用它:

  git config --global http.proxy http:// proxyuser:proxypwd@proxy.server.com:8080 

但是,我使用的是Microsoft Git Provider与Visual Studio集成。而且我无法在任何地方设置代理来连接到Git服务器。有没有一种方法可以在Visual Studio中保存Microsoft Git Provider的代理详细信息?

解决方案

没有直接的方法在Visual Studio中设置Git代理



您无需在Visual Studio中设置任何内容即可设置Git代理 - 事实上,我还没有找到在Visual Studio中直接执行此操作的任何方法,以及使用devenv.exe.config的备用答案我本人无法开始工作。






然而,有一个简单的解决方案



只要您有Git复选标记,Visual Studio就会为Windows安装Git安装期间(最新版本默认有这个)。一旦安装了Git for Windows(或任何操作系统上的Git),您可以直接在任何命令行,控制台或Powershell窗口中直接设置全局Git代理设置。



<事实上,您可以直接在Visual Studio中用 Tools / NuGet Package Manager / Package Manager Console 打开命令或Powershell提示符。 b $ b

如果安装了Git,则可以在任何命令行键入 git ,您将获得所有git命令的列表。如果这种情况没有发生,你可以直接安装Git for Windows - 我推荐你将它作为安装Git Extensions GUI应用程序的一部分,但你的里程可能会有所不同。



git命令,特别是你需要的是:


  git config --global http.proxy http :// USER:PASSWORD @ URL:PORT 
git config --global https.proxy http:// USER:PASSWORD @ URL:PORT


其中:


  • 代理地址可能为 http:// 不是 https://

  • 用户名:PASSWORD @是您的代理所需的用户名和密码

  • URL是代理的完整域名

  • PORT是代理服务器的端口,可能与http和https不同。



这将在您的全局配置文件中设置您的代理我的文档文件夹。根据您的操作系统和其他因素,该文件可能会有不同的命名或放置在其他地方。您可以随时查看此文件并使用以下命令直接编辑部分和键/值对:


  git config --global -e 


这会打开Git中当前编辑器设置中的全局配置,或者可能是系统默认的文本编辑器。您还可以通过访问repo目录并从 - global 标志中看到任何给定回购的配置文件。



在设置代理之后,您应该看到类似以下内容的文件:


  [http] 
proxy =< http:// user:pass @ url:port>
[https]
proxy =< http:// user:pass @ url:port>


您可以直接输入这些值,而不是使用config命令,或者可以删除它们以从配置中删除代理。



注意:这个文件也是user.name和user.email的地方用于存储提交 - 请参阅 [user] 部分。






其他有用的Git配置代理





1.您也可以省去 - global 或者用 - local 代替它,如果你想为当前的本地仓库设置代理(你必须在repo目录)。





2.另外,您可以为一个特定的URL设置代理,如下所示:


  git config --global http。<完整的URL以应用代理> .proxy< http: //用户:通过@网址:端口> 
git config --global https。<要使用代理的完整网址> .proxy< http:// user:pass @ url:port>


请注意,应使用完整网址(即 http:// https:// 在前面)。

<另外,如果您有多个远程回购站点,比如说来源上游


  git config --global http.upstream.proxy< http:// user:pass @ url:port> 
git config --global https.upstream.proxy< http:// user:pass @ url:port>




4.您可以设置通过将替换为代理URL,将代理替换为null。例如,如果您想要全局设置代理,然后排除公司防火墙后面的特定URL(例如企业,Github的本地版本),并且代理不处理本地地址正确。这可能对本地主机和其他特殊地址或直接IP地址也有帮助。





5.您可以检查代理是针对给定的URL包含以下内容:


  git config --get-urlmatch http.proxy< any random完整网址> 


例如:


  git config --get-urlmatch http.proxy https://github.com 



I have to use http proxy to connect to Git server. I am able to set it through Git Bash and use it too through the following command:

git config --global http.proxy http://proxyuser:proxypwd@proxy.server.com:8080

However, I am using Microsoft Git Provider integration with Visual Studio. And I am not able to set proxy anywhere to connect to Git server. Is there a way that I can save the proxy details for Microsoft Git Provider in Visual Studio?

解决方案

There is not a direct way to set a Git proxy in Visual Studio

You don't need to setup anything in Visual Studio in order to setup the Git proxy - in fact, I haven't found any way to do so within Visual Studio directly, and the alternate answer on using devenv.exe.config I was not personally able to get to work.


However, there is an easy solution

Visual Studio will install Git for Windows as long as you have Git checkmarked during install (the latest versions have this by default). Once Git for Windows (or Git in general on any OS) is installed, you can easily setup the global Git proxy settings directly at any command line, console, or Powershell window.

In fact, you can open a command or Powershell prompt directly in Visual Studio with Tools/NuGet Package Manager/Package Manager Console.

If Git is installed, you can type git at any command line and you'll get a list of all the git commands. If this does not happen, you can install Git for Windows directly - I would recommend doing that as a part of installing the Git Extensions GUI application, but your mileage may vary.

The git commands in particular you need are:

git config --global http.proxy http://USER:PASSWORD@URL:PORT
git config --global https.proxy http://USER:PASSWORD@URL:PORT

Where:

  • The proxy address likely is http:// and not https://
  • USER:PASSWORD@ is the user name and password if required for your proxy
  • URL is the full domain name of the proxy
  • PORT is the port of the proxy, and might be different for http and https

This will setup your proxy in a global config file in your "MyDocuments" folder. The file might be named differently or place somewhere else depending on your OS and other factors. You can always view this file and edit the sections and key/value pairs directly with the following command:

git config --global -e

This will open up the global config in the current editor setup in Git, or possibly the system default text editor. You can also see the config file for any given repo by being in the repo directory and leaving off the --global flag.

After setting up the proxy, you should see something like the following as a part of the file:

[http]
    proxy = <http://user:pass@url:port>
[https]
    proxy = <http://user:pass@url:port>

You can enter these values directly rather than using the config commands, or can delete them to remove the proxy from the config.

Note: This file is also where the user.name and user.email that are used for commits is stored - see the [user] section.


Other useful Git configs for proxy


1. You can also leave off the --global or replace it with --local if you want to setup the proxy for the current local repo (you must be in the repo directory when issuing the command).


2. In addition, you can setup a proxy for just a specific URL as follows:

git config --global http.<full URL to apply proxy>.proxy <http://user:pass@url:port>
git config --global https.<full URL to apply proxy>.proxy <http://user:pass@url:port>

Note that the full URL should be used (i.e. http:// or https:// in the front).


3. In addition, if you ever have multiple remote repos, say origin and upstream, which need different proxies, you can set a proxy for one specifically.

git config --global http.upstream.proxy <http://user:pass@url:port>
git config --global https.upstream.proxy <http://user:pass@url:port>


4. You can set the proxy to null by substituting "" for the proxy URL. This may be useful if, for example, you want to set the proxy globally, but then exclude a specific URL which is behind your company firewall (such as an enterprise, on premises version of Github), and the proxy doesn't handle local addresses correctly. This may also be helpful with localhost and other special addresses or direct IP addresses.


5. You can check what the proxy is for a given URL with the following:

git config --get-urlmatch http.proxy <any random full URL>

for example:

git config --get-urlmatch http.proxy https://github.com

这篇关于在Visual Studio中为Microsoft Git Provider设置代理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆