在 Visual Studio 中为 Microsoft Git Provider 设置代理
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/44285651/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Set proxy for Microsoft Git Provider in Visual Studio
提问by Saket
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:
我必须使用 http 代理连接到 Git 服务器。我可以通过 Git Bash 设置它并通过以下命令使用它:
git config --global http.proxy http://proxyuser:[email protected]: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?
但是,我正在使用 Microsoft Git Provider 与 Visual Studio 的集成。而且我无法在任何地方设置代理以连接到 Git 服务器。有没有办法在 Visual Studio 中保存 Microsoft Git Provider 的代理详细信息?
回答by LightCC
There is not a direct way to set a Git proxy in Visual Studio
没有在 Visual Studio 中设置 Git 代理的直接方法
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.
你不需要在 Visual Studio 中设置任何东西来设置 Git 代理——事实上,我还没有找到任何直接在 Visual Studio 中这样做的方法,以及使用 devenv.exe.config 的替代答案我是个人无法上班。
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.
只要你在安装过程中勾选了 Git(最新版本默认有这个),Visual Studio 就会为 Windows 安装 Git。安装 Windows 版 Git(或任何操作系统上的一般 Git)后,您可以直接在任何命令行、控制台或 Powershell 窗口中轻松设置全局 Git 代理设置。
In fact, you can open a command or Powershell prompt directly in Visual Studio with Tools/NuGet Package Manager/Package Manager Console
.
事实上,您可以直接在 Visual Studio 中使用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.
如果安装了 Git,您可以git
在任何命令行输入,您将获得所有 git 命令的列表。如果没有发生这种情况,您可以直接安装适用于 Windows 的 Git - 我建议将其作为安装 Git 扩展 GUI 应用程序的一部分,但您的里程可能会有所不同。
The git commands in particular you need are:
您特别需要的 git 命令是:
git config --global http.proxy http://USER:PASSWORD@URL:PORT git config --global https.proxy http://USER:PASSWORD@URL:PORT
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 nothttps://
- 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
- 代理地址可能是
http://
和不是https://
- USER:PASSWORD@ 是您的代理需要的用户名和密码
- URL 是代理的完整域名
- PORT 是代理的端口,对于 http 和 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:
这将在“MyDocuments”文件夹中的全局配置文件中设置您的代理。根据您的操作系统和其他因素,文件可能会以不同的方式命名或放在其他地方。您始终可以使用以下命令直接查看此文件并编辑部分和键/值对:
git config --global -e
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.
这将在 Git 的当前编辑器设置中打开全局配置,或者可能是系统默认文本编辑器。您还可以通过位于 repo 目录中并取消--global
标记来查看任何给定 repo 的配置文件。
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>
[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.
注意:此文件也是用于提交的 user.name 和 user.email 的存储位置 - 请参阅[user]
部分。
Other useful Git configs for proxy
其他有用的代理 Git 配置
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).
1.如果你想为当前本地 repo 设置代理,你也可以省略--global
或替换它--local
(发出命令时你必须在 repo 目录中)。
2. In addition, you can setup a proxy for just a specific URL as follows:
2. 此外,您可以为特定 URL 设置代理,如下所示:
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>
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).
请注意,应使用完整的 URL(即http://
或https://
在前面)。
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.
3. 另外,如果你有多个远程仓库,比如origin
和upstream
,需要不同的代理,你可以专门设置一个代理。
git config --global http.upstream.proxy <http://user:pass@url:port> git config --global https.upstream.proxy <http://user:pass@url:port>
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.
4. 您可以通过替换""
代理 URL 将代理设置为空。例如,如果您想全局设置代理,然后排除位于公司防火墙后面的特定 URL(例如企业、本地版本的 Github),并且代理不处理本地地址正确。这对于本地主机和其他特殊地址或直接 IP 地址也可能有帮助。
5. You can check what the proxy is for a given URL with the following:
5. 您可以使用以下命令检查给定 URL 的代理:
git config --get-urlmatch http.proxy <any random full URL>
git config --get-urlmatch http.proxy <any random full URL>
for example:
例如:
git config --get-urlmatch http.proxy https://github.com
git config --get-urlmatch http.proxy https://github.com
回答by mikep
You can set a proxy for Visual Studio as in https://msdn.microsoft.com/en-us/library/dn771556.aspx:
您可以在https://msdn.microsoft.com/en-us/library/dn771556.aspx 中为 Visual Studio 设置代理:
Find devenv.exe.config (the devenv.exe configuration file) in: %ProgramFiles%\Microsoft Visual Studio 14.0\Common7\IDE (or %ProgramFiles(x86)%\Microsoft Visual Studio 14.0\Common7\IDE).
In the configuration file, find the
<system.net>
block, and add this code: XML
在以下位置找到 devenv.exe.config(devenv.exe 配置文件):%ProgramFiles%\Microsoft Visual Studio 14.0\Common7\IDE(或 %ProgramFiles(x86)%\Microsoft Visual Studio 14.0\Common7\IDE)。
在配置文件中,找到
<system.net>
块,并添加以下代码:XML
<defaultProxy enabled="true" useDefaultCredentials="true">
<proxy bypassonlocal="True" proxyaddress=" HYPERLINK "http://<yourproxy:port#" http://<yourproxy:port#>"/>
</defaultProxy>
You must insert the correct proxy address for your network in proxyaddress="http://.
您必须在 proxyaddress="http://.
回答by Rubensvsx
If it helps someone, VS 2017 has a folder:
如果对某人有帮助,VS 2017 有一个文件夹:
%ProgramFiles%\Microsoft Visual Studio17\Professional\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer\Git\mingw32\etc
with a file named gitconfig
- the same as the file in C:\Users\[UserName]\.gitconfig
- where you can set the proxy configuration for VS.
使用名为的文件gitconfig
- 与中的文件相同C:\Users\[UserName]\.gitconfig
- 您可以在其中设置 VS 的代理配置。
回答by Daniel Joubert
Another approach would be to go to your user folder c:\users\<account name>
(in my case c:\users\danielj
) and create a file called .gitconfig
.
另一种方法是转到您的用户文件夹c:\users\<account name>
(在我的情况下c:\users\danielj
)并创建一个名为.gitconfig
.
paste the following:
粘贴以下内容:
[user]
name = <your name>
[user]
email = <your email address>
[http]
sslVerify = false
proxy = "http://<username>%40<domain e.g. domain.com>:#<password>@<proxy server name>:<port>"
[https]
sslVerify = false