Skip to content

Instantly share code, notes, and snippets.

@garystafford
Last active August 1, 2022 14:47
Show Gist options
  • Save garystafford/8128922 to your computer and use it in GitHub Desktop.
Save garystafford/8128922 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: …
# 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(){
export PASSWORD=my_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."
}
@mephissto
Copy link

Thanks for this example.

I've just made an update to prompt the password and not store it in the script, here is my edit : https://gist.github.com/mephissto/16436d231b64711ab3c8f971a4b2097e

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment