Getting git to work through a proxy server (in Windows)

It seems that most solutions for setting up git to work through a proxy server depends on installing cygwin and using corkscrew. Having a need to get this set up at a customer, I really didn’t want to install cygwin just for this. Let me explain my setup that works without cygwin/corkscrew.

The key to this solution is having access to connect.exe that comes with Git for Windows. If installed in the default location, this file should be found at C:\Program Files\Git\mingw64\bin\connect.exe.

Next we need to modify the ssh config file. In my environment I needed access to both GitLab and GitHub, and my config file ended up looking something like this:

Host *
 ProxyCommand "C:/Program Files/Git/mingw64/bin/connect.exe" -H {proxyserver}:{port} %h %p
 IdentityFile "C:\path\to\ssh\key"
 TCPKeepAlive yes
 IdentitiesOnly yes

Host github.com
 User git
 Port 22
 Hostname github.com

Host gitlab.domain.tld
 User git
 Port 22
 Hostname gitlab.domain.tld

This makes all ssh communication go through the proxy server. Just make sure that your ssh config file are in the correct location. In this particular environment, they have redirected home areas to a network disk, so I had to update the global ssh config file (C:\Program Files\Git\etc\ssh\ssh_config) to make it work through git.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s