githubで複数ユーザを使い分ける

githubというかgitosisはsshの鍵でユーザを判定します。
設定の仕方はhelpでも見てくだしあ。
Redirecting...
Redirecting...
Redirecting...
自分のgithubユーザとして色んなマシンからgithubを使う場合は簡単です。
上記の説明のとおりに公開鍵を追加していけばいいだけです。


で、同じマシンの同じユーザアカウントで、
複数のgithubユーザとしてgithubを使うのはどうすればいいかというと、
ホストのエイリアスを設定して別の秘密鍵を設定してやれば大丈夫です。
入門OpenSSH / 第4章 OpenSSH を使う
↓の例は複数HostNameへのSSH接続の管理ですが、
~/.ssh/config で簡単に複数ホストへのSSH接続を管理する - すぱぶろ
同一HostNameで別Hostというふうにも出来るのでそれを使います。


元々のgithubユーザで使っていた秘密鍵をid_rsaとして、
別のgithubユーザで使う秘密鍵をid_rsa.anotherとしたら、
~/.ssh/config に以下のように記述します。

# monjudoh
Host gist.github.com
HostName gist.github.com
User git
IdentityFile ~/.ssh/id_rsa
IdentitiesOnly yes
Host github.com
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa
IdentitiesOnly yes
# another
Host gist.github.com-another
HostName gist.github.com
User git
IdentityFile ~/.ssh/id_rsa.another
IdentitiesOnly yes
Host github.com-another
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa.another
IdentitiesOnly yes

git@github.com:another/hoge.git をcloneしてきたい場合、
以下のようにすれば、anotherユーザとしてcloneしてくることが出来ます。

git clone git@github.com-another:another/hoge.git

アイコンについて

githubgithub.tokenとuser.emailの設定によって
changesetにどのアイコンを出すか決めているようなので、
git config --local user.email
で、別のメールアドレスを設定しておきましょう。
これをやらないとお客さんも見るリポジトリに二次元キャラアイコンが並ぶなどという事故が起こる可能性があります。
それで別に問題がないなどという可能性もあります。