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:
Where:
http://
and nothttps://
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:
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:
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:
Note that the full URL should be used (i.e.
http://
orhttps://
in the front).3. In addition, if you ever have multiple remote repos, say
origin
andupstream
, which need different proxies, you can set a proxy for one specifically.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:
for example:
If help someone the VS 2017 has an folder(%ProgramFiles%\Microsoft Visual Studio\2017\Professional\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer\Git\mingw32\etc) with a file named "gitconfig" as the file in "C:\Users[User].gitconfig" where you can set the proxy configuration for VS.
You can set a proxy for Visual Studio as in https://msdn.microsoft.com/en-us/library/dn771556.aspx :