Skip to content

Instantly share code, notes, and snippets.

@anair-it
Created March 21, 2018 15:59
Show Gist options
  • Save anair-it/60874494394122e1ca7214a8cf1252a6 to your computer and use it in GitHub Desktop.
Save anair-it/60874494394122e1ca7214a8cf1252a6 to your computer and use it in GitHub Desktop.
Configure proxy settings to work with corporate and at home

Follow below steps to enable/disable proxy in git and maven in Windows PC.

  • Proxy configuration is turned on by default. To manually turn on, run "proxon" in git bash shell
  • To turn off proxy, run "proxoff" command in git bash shell

Add proxy commands in git bash file

Assuming you have git bash installed

  • Open c:\Users\[ME]\.bashrc

  • Add following snippet

      function proxon(){
         # environment variables are UPPERCASE even in git bash
         export PROXY_SERVER=[MY_PROXY_SERVER]
         export PROXY_PORT=8080
         export PROXY_FLAG=false
         export HTTP_PROXY="http://$PROXY_SERVER:$PROXY_PORT"
         export HTTPS_PROXY=$HTTP_PROXY
         export FTP_PROXY=$HTTP_PROXY
         export SOCKS_PROXY=$HTTP_PROXY
    
         export NO_PROXY="localhost,127.0.0.1"
    
         # Update git config to use the proxy
         git config --global http.proxy $HTTP_PROXY
         git config --system http.sslVerify false
    
         env | grep -e _PROXY -e GIT_ | sort
         echo -e "\nProxy-related environment variables set."
    
         clear
      }
    
      # Disable proxy settings
      function proxoff(){
         variables=("HTTP_PROXY" "HTTPS_PROXY" "FTP_PROXY" "SOCKS_PROXY")
    
         for i in "${variables[@]}"
         do
      	  unset $i
         done
         git config --global --unset http.proxy
         export PROXY_FLAG=true
    
         env | grep -e _PROXY -e GIT_ | sort
         echo -e "\nProxy-related environment variables removed."
      }
    
      # Turn on proxy settings by default
      proxon
    
  • Update proxy server and port as required

Update maven settings.xml

  • Update proxy info:

      <proxy>
         <id>my_proxy</id>
         <active>${env.PROXY_FLAG}</active>
         <protocol>http</protocol>
         <host>${env.PROXY_SERVER}</host>
         <port>8080</port>
         <nonProxyHosts>${env.NO_PROXY}</nonProxyHosts>
      </proxy>
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment