Difference between revisions of "Using git with a proxy"

From eLinux.org
Jump to: navigation, search
Line 55: Line 55:
* http://blogs.gnome.org/juanje/2009/07/17/git_behind_proxy/
* http://blogs.gnome.org/juanje/2009/07/17/git_behind_proxy/
* https://wiki.yoctoproject.org/wiki/Working_Behind_a_Network_Proxy - shows scripts for both 'socat' and 'nc'
* https://wiki.yoctoproject.org/wiki/Working_Behind_a_Network_Proxy - shows scripts for both 'socat' and 'nc'
* http://sitaramc.github.com/tips/git-over-proxy.html - shows socat proxy and ssh tunnel (but is not very clear?)

Latest revision as of 17:18, 10 December 2012

[as of 2012.12.10 this article is a work in progress]

I found it very difficult to set up git to use a proxy at my work environment. Here is some information that I found, that hopefully will be helpful to other people looking into this problem.

Different kinds of proxies and protocols

Before you can have git operate through a firewall via a proxy, you first have to understand what type of proxy you have, and what type of protocol you will be using to access your target git repository.

Git can operate over either http (port 80), https (port 437), use the git protocol directly (port 9418) or use the git protocol over ssh (port 22).

If you are in an environment where direct access to the internet is prohibited by a firewall, then you may be able to access the target repository you are interested in via a proxy. For example, in many corporate environments, direct access to http is not allowed, but an http firewall is provided to allow access to the world wide web. If your target repository is accessible via the http protocol on port 80, it is likely that you can access it directly from git, with no extra steps.

git urls

The prefix to the URL for a repository indicates the type of protocol (and implies the port) for accessing that respository. Note that many git publishing sites provide access via multiple protocols, so if one is unavailable it may be possible to use an alternate method to access the site.

Here are some common protocols, and some example URLs associated with them:

different kinds of proxies

There are different kinds of proxies which may be available to you.

  • http
  • socks
    • SOCKS4 vs. SOCKS5

git proxy configuration

You can configure git to use a proxy helper script to use to work with a proxy. This script is specified in the git configuration file in the [core] section, with the attribute name "gitproxy".

The helper script, by convention, is called git-proxy.sh, but you can name it anything you want, and configure git to use that:

$ git config --global core.gitproxy /path/to/bin/git-proxy.sh

Note that it is possible to use more than one proxy script, depending on the domain name of the repository. In this case, you provide multiple configuration values for the core.gitproxy configuration variable. This is explained here:

git proxy command