How do I get Git to use a proxy server?
I need to check out code from a Git server, but it shows \"Request timed out\" every time. How do I get around this?
Command to use:
git config --global http.proxy http://proxyuser:proxypwd@proxy.server.com:8080
proxyuser
to your proxy userproxypwd
to your proxy passwordproxy.server.com
to the URL of your proxy server8080
to the proxy port configured on your proxy serverNote that this works for both http and https repos.
If you decide at any time to reset this proxy and work without proxy:
Command to use:
git config --global --unset http.proxy
Finally, to check the currently set proxy:
git config --global --get http.proxy
Try to put the following to the ~/.gitconfig file:
[http]
proxy = http://proxy:8080
[https]
proxy = http://proxy:8080
[url "https://"]
insteadOf = git://
If you are using ubuntu, then do the following ...
Step 1 : Install corkscrew
$ sudo apt-get install corkscrew
Step 2 : Write a script named git-proxy.sh and add the following
#!/bin/sh
exec corkscrew <name of proxy server> <port> $*
# <name_of_proxy_server> and <port> are the ip address and port of the server
# e.g. exec corkscrew 192.168.0.1 808 $*
Step 3 : Make the script executable
$ chmod +x git-proxy.sh
Step 4 : Set up the proxy command for GIT by setting the environment variable
$ export GIT_PROXY_COMMAND="/<path>/git-proxy.sh"
Now use the git commands,such as
git clone git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
Setting git proxy on terminal
if
Set it globally once
git config --global http.proxy username:password@proxy_url:proxy_port
git config --global https.proxy username:password@proxy_url:proxy_port
if you want to set proxy for only one git project (there may be some situations where you may not want to use same proxy or any proxy at all for some git connections)
//go to project root
cd /bla_bla/project_root
//set proxy for both http and https
git config http.proxy username:password@proxy_url:proxy_port
git config https.proxy username:password@proxy_url:proxy_port
if you want to display current proxy settings
git config --list
if you want to remove proxy globally
git config --global --unset http.proxy
git config --global --unset https.proxy
if you want to remove proxy for only one git root
//go to project root
cd /bla-bla/project_root
git config --unset http.proxy
git config --unset https.proxy
Faced same issue because of multiple .gitconfig
files in windows, followed below steps to fix the same:
Step 1: Open Git BASH
Step 2: Look for .gitconfig
, executing following command:
git config --list --global --show-origin
Step 3: Copy the below content in .gitconfig
:
[http]
proxy = http://YOUR_PROXY_USERNAME:YOUR_PROXY_PASSWORD@YOUR.PROXY.SERVER:YOUR.PROXY.SERVER.PORT
sslverify = false
[https]
proxy = http://YOUR_PROXY_USERNAME:YOUR_PROXY_PASSWORD@YOUR.PROXY.SERVER:YOUR.PROXY.SERVER.PORT
sslverify = false
[url "http://github.com/"]
insteadOf = git://github.com/
[user]
name = Arpit Aggarwal
email = aggarwalarpit.89@gmail.com
As an alternative to using git config --global http.proxy address:port
, you can set the proxy on the command line:
git -c "http.proxy=address:port" clone https://...
The advantage is the proxy is not persistently set. Under Bash you might set an alias:
alias git-proxy='git -c "http.proxy=address:port"'