secretbase.log

.NET/C#/Pythonなど

Git for Windows/msysgit で ユーザー名、パスワードの入力頻度を下げる

複数のリポジトリを clone する必要があり、一発 clone するスクリプト書いた。

社内の認証がhttpによる認証のため、毎回user/passwordを入力するのがだるい。
そこで、 http://$user:$password@example.co.jp/git/reponame
みたいな感じで、URL に埋め込んだら動いた。

しかし、git remote -v で URLに平文で丸見え。だめである。
調べたら、cache する仕組みがあるようだ。

環境

結論

まず、結論を。
wincred を用いる。wincred は Git に同梱されている。

$ git config --global credential.helper wincred

  
 
 
 
いくつかの方法を試したので記録として残しておきます。

credential cache を用いる(Linux)

$ git config --global credential.helper cache

で設定が可能。Linux(debian)上では動作した。

しかし msysgit 上ではエラーになってしまった。

git: 'credential-cache' is not a git command. See 'git --help'.

$ git fetch origin master
git: 'credential-cache' is not a git command. See 'git --help'.
..

git-credential-winstore を使う (Git for Windowsの場合)

ぐぐると、stackoverflowに。
http://stackoverflow.com/questions/11693074/git-credential-cache-is-not-a-git-command

○手順

  • ダウンロードする

http://gitcredentialstore.codeplex.com/
ここから git-credential-winstore.exe をダウンロードする。現在の安定版は 1.2 。

  • 実行する
  • 設定する

$ git config --global credential.helper winstore

下記のようなダイアログが出現しユーザー名とパスワードが一時的に保存されます。
f:id:cointoss1973:20140521130545p:plain

実行

社内

$ time git fetch origin master
..
real 0m21.099s
user 0m0.000s
sys 0m0.015s

社外 (bitbucket)

$ time git fetch bb master
..
real 0m43.869s
user 0m0.015s
sys 0m0.015s

めっちゃ遅い。。

1.4 Beta

$ time git fetch bb master
..
real 1m23.322s
user 0m0.015s
sys 0m0.062s

$ time git fetch origin master
..
real 1m0.874s
user 0m0.000s
sys 0m0.015s

もっと遅い。



git-credential-wincred

git-credential-wincred.exe を試してみる。
こちらは、Git同梱。

$ git config --global credential.helper wincred

社内

$ time git fetch origin master
..
real 0m0.403s
user 0m0.015s
sys 0m0.000s

社外

$ time git fetch bb master
..
real 0m7.669s
user 0m0.015s
sys 0m0.000s

これでいこう。