gitプロトコルをhttps proxy経由で使う

何故かオフィスとgithub.com間の通信速度が激遅だったのでproxyを介すようにした。

corkscrew を使用してgitプロトコルのままproxyを通すことも出来るらしいが、手元の環境だと上手くいかなかったので、進捗あればまた書きます(願望)。

https proxyを設定する

httpsのproxyを追加する

※ ここでproxy.localproxyサーバのアドレス、3128proxyサーバのポートを指定する

$ git config --global https.proxy http://proxy.local:3128

確認する

git config --list
===
https.proxy=https://proxy.local:3128
===

ここまででhttpsスキームでの通信はproxy経由で行われるようになる。

git@github.com:〜の通信でもproxyを通すようにする

gitconfigにurl.<foo>.insteadOf <bar>を設定することで、<foo>エイリアスとして<bar>が使えるような感じになる。 これによって既存のgitスキームで設定されているローカルリポジトリを変更せずともhttps proxyを通すことが可能となる。

insteadOfを設定する

$ git config --global url."https://github.com/".insteadof git@github.com:

確認する

git config --list
===
url.https://github.com/.insteadof=git@github.com:
===

これで普通にgit@github.com:scala/scala.gitなどとすると、実際はhttps proxyで通信が行われるようになる。

参考