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

これでいこう。

分散バージョン管理の機能比較まとめ

DVCSで有名なものですと、 Git , Mercurial, Bazaar があります。
最近では、Veracity という分散バージョン管理も出てきました。どのように違ってどういう基準で選ぶと良いか悩みますね。これらの違いはなんでしょうか?
そこで、比較資料をまとめてみました。

バージョン管理ソフトウェアの比較資料

従来の集中型を含めたバージョン管理ソフトウェアの比較資料

Gitポケットリファレンス

Gitポケットリファレンス

入門TortoiseHg + Mercurial

入門TortoiseHg + Mercurial

Visual Studio にて設定すべき .gitignore / .hgignore

.gitignore や .hgignore で管理対象から無視することができるのはご存知ですよね。
Visual Studio にて無視するファイル一覧をMSDNで探したけど無かったので stackoverflow で調べたらあったのでメモ。あと、教えてもらった方法も追記。

  1. stackoverflow の回答例
  2. github / .gitignore を用いる方法

無視ファイルの設定

.gitignore の場合

gitの場合は、 .gitignore をおいておきます。

.hgignore

.hgignore *1 に下記内容を記載してください。Mercurialの場合の無視ファイルは、デフォルトは正規表現で記述するので、glob文法(SHELL形式のパターンマッチングとかのやつ)にするため一行目 *2に syntax:glob と 記載します。

syntax:glob
*.obj
*.exe
*.exp
*.pdb
*.dll
*.user
*.aps
*.pch
*.vspscc
*_i.c
*_p.c
*.ncb
*.suo
*.tlb
*.tlh
*.bak
*.cache
*.ilk
*.log
*.zip
[Dd]ebug*/
*.lib
*.sbr
Thumbs.db
[Ll]ib/
[Rr]elease*/
[Tt]est[Rr]esults/
_UpgradeReport_Files/
_ReSharper.*/

github による gitginore 設定集 追記

github に 設定したら便利な .gitignore の設定集がありますので、そちらも参考にされるといいですね*3


感想

sln (ソリューションファイル) は 無視ファイルにはしないんですね。1プロジェクトだと無視したりしています。stackoverflowの回答例に追加して bin obj フォルダが指定が合ったほうがよさそう。

いただいたコメント

Twitter上でリプライ頂きました。とても参考になります。ありがとうございます。





*1:詳しくは、hg help ignore でヘルプが見られます

*2:syntaxを記述したそれ以降の文法が変わります

*3:id:kei10in さんありがとう

Git と Mercurial が Subversion より優れている点

リポジトリの初期化

  hg init
  • Subversion
  svnadmin create /path/to/repo
  svn import http://long.url.to/repo yourwork
  rm -R yourwork
  svn checkout http://long.url.to/repo yourwork

そうなんです。もちろん Subversion でも一人で始めることができます。しかし「うぁー、めんどくせー!!」ってことなんです。
ひとりでも"簡単"に始められるDVCSをオススメします。

proxy 経由で 社内から github にアクセスする方法

簡単そうでなかなかできませんでしたが、ssh経由 github にアクセスできましたのでその作業手順をご紹介します。

環境

つかったもの

connect.c の準備

まず connect.c をダウンロードして適当なディレクトリにおきます。下記は tools を作成してその下におきました。
ソースコードのコメントに記載してあるように、コンパイルします。

tkondou@hostname ~/tools
$ gcc connect.c -o connect

$ ls
connect.c  connect.exe

connect.exe ができました。

SSH Public キーの作成

$ ssh-keygen -t rsa -C "foo@bar.com"

にて ~/.ssh/id_rsa と id_rsa.pub ができます。
id_rsa..pub の内容を github の Account Settings の SSH Public Keys に登録してください。

~/.ssh/config を準備

$ cat  ~/.ssh/config
ProxyCommand C:/cygwin/home/tkondou/tools/connect.exe  -H proxy.mycompany.co.jp:80 %h %p

Host github.com
User git
Port 22
Hostname github.com
IdentityFile "C:\cygwin\home\tkondou\\.ssh\id_rsa"
TCPKeepAlive yes
IdentitiesOnly yes

Host ssh.github.com
User git
Port 443
Hostname ssh.github.com
IdentityFile "C:\cygwin\home\tkondou\\.ssh\id_rsa"
TCPKeepAlive yes
IdentitiesOnly yes

connect.exeを指定するパスは / で指定する必要がありますので注意してください。
proxy.mycompany.co.jp:80 の部分は、各自のプロキシ環境に合わせてください。
tkondouはcygwinのユーザ名ですのでこちらも適切に変更してください。

ssh での接続確認

$ ssh  -F ~/.ssh/config ssh.github.com
The authenticity of host '[ssh.github.com]:443 (<no hostip for proxy command>)' can't be established.
RSA key fingerprint is 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '[ssh.github.com]:443' (RSA) to the list of known hosts.
PTY allocation request failed on channel 0

PTY allocation request failed on channel 0というエラーでOKです。
これは git のコマンドがないためです。

git clone にて github のリポジトリのコピーをつくる

cointoss1973 の github アカウントから stream を git 経由で落としてきます。

tkondou@hostname ~/workspace
$ git clone ssh://git@ssh.github.com:443/cointoss1973/stream.git
Cloning into stream...
remote: Counting objects: 7, done.
remote: Compressing objects: 100% (7/7), done.
Receiving objects: 100% (7/7), 4.60 KiB, done.
remote: Total 7 (delta 0), reused 7 (delta 0)

ssh のホスト名を間違っていたみたいでしばらくハマりましたが、無事にアクセスすることができました。




入門Git

入門Git