15

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:[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?

1
  • I'm confused what wasn't working for you with the 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.)
    – LightCC
    Sep 6, 2017 at 21:39

4 Answers 4

24

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
6
  • 1
    Thank you - this fixed my problem connecting to our git repository... But seriously, we're in 2018, and having to make Proxy settings using the command line ? Does Microsoft not do user-friendliness anymore...? Mar 28, 2018 at 8:29
  • 1
    @MikeGledhill Are you implying that Microsoft ever did user-friendliness? :) For the record, you can use GIT Extensions open source tool to setup all the same things with a visual GUI - that's what I use for most Git operations, but occasionally you do need to revert to the command line tool. Visual Studio does not do Git natively, it interfaces to Git, so don't expect all functionality to be available, just the ones that provide the most value to the most customers. Feel free to submit an enhancement request (and where to do so...). :)
    – LightCC
    Apr 2, 2018 at 17:50
  • 1
    Ensure the http proxy is set as I only had httpsdefined in my .gitconfig which caused the connection error. I tried setting the proxy with an https url as per the answer by @mikep and got a ServiceConnectionManager error from Visual Studio about not supporting https urls. I reverted the devenv.exe.config file and the update to .gitconfig worked. Jul 9, 2019 at 22:33
  • Is there any way for username and password to not be hardcoded in the proxy URL? Jan 27, 2020 at 16:18
  • @RossPresser You can try without the username and password, and see what happens - it may ask you to enter the info each time in a command window somewhere. Also, try just username and see if VS gives a password window. I don't have this situation so unsure. Since this post, the "Windows Credential Manager" or something with a very similar name has come out, that Git does interact with - you could check that out and see if the proxy username/password is covered. Also note - it is only hardcoded in your personal .gitconfig. I'm surprised your proxy doesn't use SSO or similar to login though.
    – LightCC
    Jan 27, 2020 at 16:52
9
+200

You can set a proxy for Visual Studio as in https://msdn.microsoft.com/en-us/library/dn771556.aspx :

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

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

2
  • 2
    What exactly needs to be replaced with the proxy address? The proxyaddress= statement is a mess as written. Do you replace http://<yourproxy:port# both times, and excluding the trailing >" on the second instance? Either way, I've tried both and it doesn't seem to actually work (or do anything).
    – LightCC
    Sep 6, 2017 at 21:37
  • That <proxy> element is defined in learn.microsoft.com/en-us/dotnet/framework/configure-apps/…
    – Minqi Pan
    Sep 3 at 12:54
5

If it helps someone, VS 2017 has a folder:

%ProgramFiles%\Microsoft Visual Studio\2017\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.

1
  • It appears this is where the MS Team Explorer/TF package installs Git for Windows when using this toolset. The Git\mingw32\etc\gitconfig file is likely the "system" gitconfig file and will affect all users on the PC. You should be able to open it for edit with git config -e --system. The .gitconfig' in the users home directory will only affect that particular user, and can be opened with git config -e --global` at the command line.
    – LightCC
    Jan 7, 2020 at 21:04
3

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.

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

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.