LoginSignup
20
26

More than 5 years have passed since last update.

proxy環境下でgit cloneするまで(503エラーを超えて)

Last updated at Posted at 2017-03-29

proxy環境下でgit cloneしようとして悪戦苦闘した話。

結論

git のバージョン上げて環境変数no_proxyを設定しましょう。

環境

Bash on Ubuntu on Windows (10 pro)

環境変数設定

まずは環境変数を設定。

$ export http_proxy="http://example.co.jp:xxxx"
$ export https_proxy="https://example.co.jp:xxxx"

(ここで'.co'を入れ忘れてて30分ぐらい失った。すごく恥ずかしい)

git のバージョンと設定

バージョンは以下の通り。
とりあえずapt-get install git でいれました。

$ git --version
git version 1.9.1

以下のように設定。
会社ではgitlabを使用しているので、そこで使ってる名前やアドレスを登録しました。

git config --global user.name taro
git config --global user.email taro.com
git config --global http.sslverify false
git config --global credential.helper cache
git config --global http.proxy http://example.co.jp:xxxx
git config --global https.proxy https://example.co.jp:xxxx

とりあえずgit clone

とりあえずcloneしてみました(sshのアドレスじゃなくてhttpであることに注意)

$ git clone http://git.example.com/taro/sample.git
Cloning into 'sample'...
fatal: unable to access 'http://git.example.com/taro/sample': The requested URL returned error: 503

まさかの503エラー。

調べてみたところ、このサイト(Gitを社内(Proxy環境下)で使うときは気をつけましょう)と同じ状況でした。

どうやら環境変数no_proxyの設定が必要らしい。
ただし、このバージョン(1.9.1)のgitはno_proxyに対応していない(参照していない?)らしい。
(Gitがいつの間にかno_proxyに対応してた)

なのでgitのバージョンを上げる

gitのバージョンを上げる

上げるといっても、デフォルトのapt-getで入れると1.9.1が入ってしまうため、
一工夫いれる。(Ubuntu 14.04 で Git の最新を使う)

$ sudo add-apt-repository ppa:git-core/ppa
$ sudo apt-get update
$ sudo apt-get upgrade

コピペなのでsudo ついちゃってるけど、BoWだと起動時にデフォルトで
rootユーザとしてログインしてるからなくても動くと思います。

バージョンが上がっていることを確認。

$ git --version
git version 2.11.0

環境変数no_proxyの設定

export no_proxy="127.0.0.1,localhost,192,168.*,git.example.com"

ここら辺の細かい値は各自調整。
(おそらく)

git clone(リベンジ)

$ git clone http://git.example.com/taro/sample.git
fatal: destination path 'sample' already exists and is not an empty directory.

ようやく成功しました!
(fatalと書いてありますが、空のリポジトリをcloneしたから吐かれているだけで、ちゃんとディレクトリにはcloneされてます)

感想

プロキシ周りは勉強不足すぎてトラウマしかできませんでした。
皆さんも気を付けましょう!

20
26
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
20
26