在公司裡因為 firewall 的關係,沒辦法從公司裡面用 git 存取 git:// 的 repository,因此必須想辦法「翻牆」。以下簡述方法:

首先,在外面要有台 SSH server「接應」,利用 SSH tunnel 當作 socks server:

SHELL> ssh -D5487 <account>@<server-address>

然後,安裝 tsocks 這套軟體,在 FreeBSD 裡就是 /usr/ports/net/tsocks,在 Ubuntu 裡就直接找 tsocks 裝即可。裝好後設定檔在 /etc/tsocks.conf/usr/local/etc/tcosks.conf,修改其內容,將 default server 設定改成如下:

# Default server
# For connections that aren't to the local subnets or to 150.0.0.0/255.255.0.0
# the server at 192.168.0.1 should be used (again, hostnames could be used
# too, see note above)
server = 127.0.0.1
# Server type defaults to 4 so we need to specify it as 5 for this one
server_type = 5
# The port defaults to 1080 but I've stated it here for clarity.
server_port = 5487

然後在執行 git 時,前面冠以 tsocks 指令如下即可:

SHELL> tsocks git clone git://foo.com/bar.git bar

搞定收工。