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?
If you have tsocks or proxychains installed and configured, you can
$ tsocks git clone <you_repository>
or
$ proxychains git clone <you_repository>
to make it shorter, I created a symbol link /usr/bin/p
for proxychains
, so I can use it like this
p git clone <you_repository>
and I can use it to proxy any command,
p <cmd-need-be-proxied>
by the way, proxychains is not updated for a long time, you may wanna try proxychians-ng
I have tried all the above answers and nothing worked for me, as there was a proxy password encoding issues.
This command worked:
git config --global http.proxy http://username@proxy.example.com:PortNumber
Do not enter the password in your command. It will dynamically ask for when you try to connect to any git repo.
There's something I noticed and want to share here:
git config --global http.proxy http://<proxy address>:<port number>
The method above will not work for SSH URLs (i.e., git@github.com:<user name>/<project name>.git
):
git clone git@github.com:<user name>/<project name>.git // will not use the http proxy
And things will not change if we set SSH over the HTTPS port (https://help.github.com/en/articles/using-ssh-over-the-https-port) because it only changes the port (22 by default) the SSH connection connects to.
Set a system variable named http_proxy
with the value of ProxyServer:Port
.
That is the simplest solution. Respectively, use https_proxy
as daefu pointed out in the comments.
Setting gitproxy (as sleske mentions) is another option, but that requires a "command", which is not as straightforward as the above solution.
References: http://bardofschool.blogspot.com/2008/11/use-git-behind-proxy.html
For the git protocol (git://...), install socat and write a script such as:
#!/bin/sh
exec socat - socks4:your.company.com:$1:$2
make it executable, put it in your path, and in your ~/.gitconfig
set core.gitproxy
to the name of that script.
For windows users: if git config
or set http_proxy=
doesn't work, this answer may help:
replace the git://
protocol of the git repository with http://
. Note, you'll have to set the http_proxy
first, anyways.