Skip to content

Instantly share code, notes, and snippets.

@mephissto
Forked from garystafford/git_proxy_functions.sh
Created November 16, 2016 15:38
Show Gist options
  • Save mephissto/16436d231b64711ab3c8f971a4b2097e to your computer and use it in GitHub Desktop.
Save mephissto/16436d231b64711ab3c8f971a4b2097e to your computer and use it in GitHub Desktop.
Gist for blog post 'Easy Configuration of Git for Windows on a Corporate Network'.Easily turn proxy-related settings on and off for Git for Windows.1) Add these functions to your ~\.bashrc file, 2) Change PASSWORD, PROXY_SERVER, and PROXY_PORT default values, 3) Open new Git Bash interactive shell window and execute function before using git: pr…
# updated version here: https://gist.github.com/garystafford/8196920
# loosely based on post from ArchWiki and Alan Pope
# https://wiki.archlinux.org/index.php/proxy_settings
# this is alternative to git config
# configure proxy for git while on corporate network
function proxy_on(){
read -s -p "Enter Password: " PASSWORD
export PROXY_SERVER=my_proxy
export PROXY_PORT=my_port
# $USERDOMAIN, $USERNAME, $USERDNSDOMAIN
# are existing Windows environment variables on my computer
# on Windows env vars are UPPERCASE even in git bash
export HTTP_PROXY="http://$USERDOMAIN\\$USERNAME:$PASSWORD@$PROXY_SERVER:$PROXY_PORT"
export HTTPS_PROXY=$HTTP_PROXY
export FTP_PROXY=$HTTP_PROXY
export ALL_PROXY=$HTTP_PROXY # for SOCKS use ALL_PROXY or SOCKS_PROXY?
export NO_PROXY="localhost,127.0.0.1,$USERDNSDOMAIN"
# optional for debugging
export GIT_CURL_VERBOSE=1
# optional Self Signed SSL certs and
# internal CA certificate in an corporate environment
export GIT_SSL_NO_VERIFY=1
env | grep -e _PROXY -e GIT_ | sort
echo -e "\nProxy-related environment variables set."
}
# remove proxy settings when off corporate network
function proxy_off(){
variables=( \
"PASSWORD" "PROXY_SERVER" "PROXY_PORT" \
"HTTP_PROXY" "HTTPS_PROXY" "FTP_PROXY" "ALL_PROXY" \
"NO_PROXY" "GIT_CURL_VERBOSE" "GIT_SSL_NO_VERIFY" \
)
for i in "${variables[@]}"
do
unset $i
done
env | grep -e _PROXY -e GIT_ | sort
echo -e "\nProxy-related environment variables removed."
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment