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
git config
statement? I've tried that (along with https statement as well) and it seems to have permanently changed it in my Git for Windows settings. i.e. I can clone from both Visual Studio and other Git programs (directly at git bash or in Git Extensions, etc.)