Set up proxy on GIT

17 April 2016 Contribute to this post

Add this to your .bash_profile (remember to update the proxy settings).

PROXY=http://username:password@proxy-url:port

#-------------------------------------------------------------
# Setup proxy on/off switch
#-------------------------------------------------------------
alias pon='set_proxy';
alias pof='unset_proxy';
set_proxy() {
	export http_proxy=$PROXY
	export https_proxy=$PROXY
	export HTTP_PROXY=$PROXY
	export HTTPS_PROXY=$PROXY
	git config --global http.proxy $PROXY
	git config --global https.proxy $PROXY
	echo --- proxy on
}
unset_proxy() {
	unset HTTP_PROXY
	unset HTTPS_PROXY
	unset http_proxy
	unset https_proxy
	git config --global --unset http.proxy
	git config --global --unset https.proxy
	echo --- proxy off
}

From command prompt, set/unset your proxy with:

pon # proxy on

pof # proxy off