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?
Alternatively, how can I set a proxy server?
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?
Alternatively, how can I set a proxy server?
The command to use:
git config --global http.proxy http://proxyuser:[email protected]: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 repositories.
If you decide at any time to reset this proxy and work without proxy:
The command to use:
git config --global --unset http.proxy
Finally, to check the currently-set proxy:
git config --global --get http.proxy
http://
for both http and https. –
Bricker %40
as a replacement for the @
in username/ password string, though I've not tested this myself. Hope it helps. :-) –
Commensurate https.proxy
in the git-config(1) manual. It doesn't work. The http.proxy
is the only documented option for HTTP proxy that works for both HTTP and HTTPS clone URLs. –
Captivity --global
when you are using username@password
is a bad idea as you are then letting every other user of the machine use your username & password. Use --user
for any "global" setting that are specific to a user and --local for any that are specific to the checked out repo that you are currently in the directory for omitting the scope implies --local
but it is nice to be specific. –
Psychopathy git config --global http.sslVerify false
afterwards. –
Crematory git config --global https.proxy 'socks://127.0.0.1:1088'
works for me –
Chancechancel This worked for me, in Windows XP behind a corporate firewall.
I didn’t have to install any local proxy or any other software besides git v1.771 from http://code.google.com/p/msysgit/downloads/list?can=3
git config --global http.proxy http://proxyuser:[email protected]:8080
git config --system http.sslcainfo /bin/curl-ca-bundle.crt
git remote add origin https://mygithubuser:[email protected]/repoUser/repoName.git
git push origin master
proxyuser = the proxy user I was assigned by our IT department. In my case, it is the same Windows user I use to log in to my PC, the Active Directory user.
proxypwd = the password of my proxy user
proxy.server.com:8080 = the proxy name and port, I got it from Control Panel, Internet Options, Connections, LAN Settings button, Advanced button inside the Proxy Server section, use the servername and port on the first (http) row.
mygithubuser = the user I use to log in to github.com
mygithubpwd = the password for my github.com user
repoUser = the user owner of the repository
repoName = the name of the repository
git config --global http.sslcainfo MY_NEW_CERTS_BUNDLE.crt
plus certificates downloaded as described in simplicidade.org/notes/archives/2011/06/… (thanks to: https://mcmap.net/q/13487/-how-do-i-pull-from-a-git-repository-through-an-http-proxy) did it for me! –
Gallard git://
protocol. –
Dinadinah https
or http
if available from the remote Git repo allows. –
Lobito 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: Use Git behind a proxy
http_proxy
is required for HTTP URLs and https_proxy
is required for HTTPS URLs. Alternatively, one could just set all_proxy
for all URLs. See ENVIRONMENT
section in curl(1). However, while setting git-config options, http.proxy
is used for both HTTP and HTTPS URLs. See http.proxy
in git-config(1). –
Captivity The requested URL returned error: 501
. –
Dwelt 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"'
git -c "http.proxy=http://address:port"
–
Yong If the command line way of configuring your proxy server doesn't work, you can probably just edit .gitconfig (in the root of your profile, which may hide both in C:\Documents and Settings and on some network drive) and add this:
[http]
proxy = http://username:[email protected]:8080
Your mileage may vary though. This only covers the first step of the command line configuration. You may have to edit the system Git configuration too and I don’t have any idea where they hid that.
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
"$@"
instead of $*
. See your shell manual for more details. –
Chicken 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:[email protected]:YOUR.PROXY.SERVER.PORT
sslverify = false
[https]
proxy = http://YOUR_PROXY_USERNAME:[email protected]:YOUR.PROXY.SERVER.PORT
sslverify = false
[url "http://github.com/"]
insteadOf = git://github.com/
[user]
name = Arpit Aggarwal
email = [email protected]
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., [email protected]:<user name>/<project name>.git
):
git clone [email protected]:<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.
Try to put the following in the ~/.gitconfig file:
[http]
proxy = http://proxy:8080
[https]
proxy = http://proxy:8080
[url "https://"]
insteadOf = git://
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.
socat STDIO PROXY:%proxy%:%1:%2,proxyport=%PROXYPORT%
–
Doorbell set GIT_PROXY_COMMAND=path\to\script
to make GIT use the proxy without messing with git config. –
Doorbell I work on Windows XP at work (state/government), so I did my research and found this here and it worked for me.
The http_proxy Environment Variable
If you use a proxy server or firewall, you may need to set the http_proxy environment variable in order to access some URL from the commandline.
Example: Installing PPM for Perl or applying an RPM file in Linux, updating Ubuntu
Set the http_proxy variable with the hostname or IP address of the proxy server:
http_proxy=http:// [proxy.example.org]
If the proxy server requires a user name and password, include them in the following form:
http_proxy=http:// [username:[email protected]]
If the proxy server uses a port other than 80, include the port number:
http_proxy=http:// [username:[email protected]:8080]
Windows XP
Set the http_proxy environment variable using the command specific to your shell (e.g., SET or export). To make this change persistent, add the command to the appropriate profile file for the shell. For example, in Bash, add a line like the following to your .bash_profile or .bashrc file:
In addition of these answers, I found helpful to consider these two points:
One may need to enforce an authentication scheme:
[http]
# https://github.com/git/git/blob/master/Documentation/config.txt
proxyAuthMethod = anyauth|basic|digest|negotiate|ntlm
Also, typically with an NTLM authentication schema, one may need to provide the AD domain explicitly.
In Git Bash:
echo %userdomain%
And update the http.proxy accordingly:
git config --global http.proxy http://DOMAIN\\proxyuser:[email protected]:8080
Anyway, investigation may be helped by adding CURL logs:
export GIT_CURL_VERBOSE=1
git config --global http.proxyAuthMethod basic
. Git gersion 2.8.3 didn't send in any authentication until I set this config parameter. –
Miramontes If you have tsocks or proxychains installed and configured, you can do
tsocks git clone <your_repository>
or
proxychains git clone <your_repository>
To make it shorter, I created a symbolic link, /usr/bin/p
, for proxychains
, so I can use it like this
p git clone <your_repository>
And I can use it to proxy any command,
p <cmd-need-be-proxied>
By the way, proxychains has not been updated for a long time, and you may want to try proxychians-ng instead.
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 a 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 the 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 the current proxy settings:
git config --list
If you want to remove the proxy globally:
git config --global --unset http.proxy
git config --global --unset https.proxy
If you want to remove the proxy for only one Git root:
// Go to the project root
cd /bla-bla/project_root
git config --unset http.proxy
git config --unset https.proxy
https.proxy
is invalid config 🙃. Only the configuration item named http.proxy
exists. see: git-scm.com/docs/git-config/2.9.5#Documentation/… –
Juristic Here is the proxy setting:
git config --global http.proxy http://<username>:<pass>@<ip>:<port>
git config --global https.proxy http://<username>:<pass>@<ip>:<port>
I followed the most of the answers which was recommended here. First I got the following error:
fatal: unable to access 'https://github.com/folder/sample.git/': schannel: next InitializeSecurityContext failed: Unknown error (0x80092012) - The revocation function was unable to check revocation for the certificate.
Then I have tried the following command by @Salim Hamidi
git config --global http.proxy http://proxyuser:[email protected]:8080
But I got the following error:
fatal: unable to access 'https://github.com/folder/sample.git/': Received HTTP code 407 from proxy after CONNECT
This could happen if the proxy server can't verify the SSL certificate. So we want to make sure that the ssl verification is off (not recommended for non trusted sites), so I have done the following steps which was recommended by @Arpit but with slight changes:
1.First make sure to remove any previous proxy settings:
git config --global --unset http.proxy
2.Then list and get the gitconfig content
git config --list --show-origin
3.Last update the content of the gitconfig file as below:
[http]
sslCAInfo = C:/yourfolder/AppData/Local/Programs/Git/mingw64/ssl/certs/ca-bundle.crt
sslBackend = schannel
proxy = http://proxyuser:[email protected]:8080
sslverify = false
[https]
proxy = http://proxyuser:[email protected]:8080
sslverify = false
I have tried all the previous answers and nothing worked for me, as there was a proxy password encoding issues.
This command worked:
git config --global http.proxy http://[email protected]:PortNumber
Do not enter the password in your command. It will dynamically ask for when you try to connect to any Git repository.
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, anyway.
After tirelessly trying every solution on this page, my workaround was to use an SSH key instead!
To change https.proxy
config for a single repository (not global git config) before a new clone (you can not change repo git config before repository exists)
cd /path/to/new/clone/
git init .
git config http.proxy http://...myProxy.com:myPort
git config https.proxy https://...myProxy.com:myPort
git remote add origin https://github.com/opencv/opencv.git
git fetch origin
git checkout -b master --track origin/master
Note: I needed https.proxy
(not http.proxy
) to have it working.
Note: you can find your proxy settings on Windows 10 at Settings -> Network&Internet -> Proxy -> Address + Port
An alternative to using a proxy is to use SSH
In the Git configurations, configure the origin remote on the SSH address. Then use the ssh-keygen command, which gives you a public key that you can set in your GitLab or Gitab account settings and login accordingly done...
Verify which remotes are using by running git remote -v
in your Git client.
If this is http(s) URL, changed it to ssh address , run: git remote set-url <remote name, e.g. origin> <new SSH URL>
.
For example,
git remote set-url [email protected]:example/myproject.git
To generate SSH key for login, run: ssh-keygen -o
. This command generate public (id_rsa.pub file) and private keys.
Copy public key contents. (from id_rsa.pub file)
Go to GitLab, GitHub, etc. profile section → setting/ssh-key. Create a new SSH key and paste the public key contents
Since no one mentioned this way, I`ll share what worked for me:
git config --global http.proxy 'socks5://127.0.0.1:1080'
git config --global https.proxy 'socks5://127.0.0.1:1080'
Changing 127.0.0.1 to the IP/URL for the proxy and the port.
© 2022 - 2024 — McMap. All rights reserved.