Set proxy for Microsoft Git Provider in Visual Studio

前端 未结 4 2239
有刺的猬
有刺的猬 2021-01-02 09:30

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 htt         


        
相关标签:
4条回答
  • 2021-01-02 09:58

    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.

    0 讨论(0)
  • 2021-01-02 10:00

    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
    
    0 讨论(0)
  • 2021-01-02 10:05

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

    0 讨论(0)
  • 2021-01-02 10:10

    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
    
    0 讨论(0)
提交回复
热议问题