22

I'm wondering how git push works. I'm behind a proxy and even configuring it in my PhpStorm soft doesn't work.

So, I'm wondering how it is sent trough network, I guess using the port 80 for HTTP and 443 for HTTPS.

I read a bunch of threads on SO but couldn't figure out what's wrong there. I guess "my" proxy doesn't have WebDAV enabled as explained here: Can't push to github through proxy

But I would like to know if anything else could be the source of the issue here, knowing that all ports are closed, excepted 80, 22 and 443.

git remote -vv
origin  https://Vadorequest@bitbucket.org/Vadorequest/vadorequest.git (fetch)
origin  https://Vadorequest@bitbucket.org/Vadorequest/vadorequest.git (push)

Solution:

Not secured proxy (http)

If the proxy is not secure then you can configure it using:

git config --global http.proxy http://user:password@host:port

And disable it using:

git config --global --unset-all http.proxy

Secured proxy (https)

git config --global https.proxy https://user:password@host:port

And disable it using:

git config --global --unset-all https.proxy

Note that if you are under Windows and using TortoiseGit, you can set the proxy settings from the software itself. (Network tab)

If you're using Cygwin then be aware that if you set the global config it will be set only for the current environment. (Using cmd.exe will set it for Windows, but using the cygwin console will set it for cygwin only)

So, if you're using Git through an IDE (PhpStorm, WebStorm) be sure to have set the config in the environment used by the IDE, or it will not work.

Be also aware that if you have set the proxy in git setting and you're not behind the proxy, it will not work neither. (i.e: You've set it at work and it works fine, but when you're using it at home it doesn't work anymore while it used to work before)

Community
  • 1
  • 1
Vadorequest
  • 16,593
  • 24
  • 118
  • 215
  • 2
    The protocol git use depend on how the remotes are configured. You can check with `git remote -vv`. Paste the results here so we can help more. – Antoan Milkov Oct 13 '14 at 12:03
  • Added on the main post. – Vadorequest Oct 13 '14 at 12:51
  • Note that if your password contains an `@`, you'll need to write something like this to make it work: `https://"user:password"@host:port`, basically just put quotes around the user:pwd – Vadorequest Mar 03 '15 at 15:53
  • I don't know why my Git still times out after I configured HTTP proxy with the following command `git config --global http.proxy http://127.0.0.1:1080`. Do you have any idea? – KaiserKatze Nov 20 '18 at 15:49

4 Answers4

11

If your proxy allow access without user and password, then you can use:

git config --global https.proxy https://proxy.company.com:8888

If your proxy need user & password then:

git config --global https.proxy https://user:password@proxy.company.com:8888

Be sure to replace 8888 with your real proxy port.
Be sure to replace proxy.company.com with your real proxy server name or IP address.

Tell me if this helps.

Antoan Milkov
  • 2,152
  • 17
  • 30
  • 1
    I'll try with `http.proxy`, I don't believe the connexion is secure. What will happen if I'm at home without proxy? I guess this setting won't mes up my git when I'm not behind the proxy but just want to make sure. I'll try soon. – Vadorequest Oct 14 '14 at 06:06
  • What if my password contains '@' symbol – shakeel Dec 04 '16 at 10:43
2

If you're behind an ntlm proxy where you need to specify domain, username and password I suggest using cntlm. You just need to configure cntlm with the proxy credentials then use localhost:3128 in the git config command.

Silvio
  • 21
  • 1
2

The http and https proxy has been mentioned above:

git config --global http.proxy http://127.0.0.1:8888
git config --global https.proxy http://127.0.0.1:8888

but the ssh proxy is different, you should add this under ~/.ssh/config, for windows user:

Host github.com
   User git
   ProxyCommand connect -S 127.0.0.1:8888 -a none %h %p

for linux user:

ProxyCommand 'nc -X 5 -x localhost:8888 %h %p'
Jay
  • 738
  • 8
  • 14
1

To avoid each time using below command for different repositories :

git config --global https.proxy https://proxy.company.com:8888

set the environnementale variable as below and chill :

export https_proxy=https://username:password@proxy_ip:port
ross
  • 111
  • 1
  • 2
  • 9