複数のGitHubアカウントを使い分ける
【1】~/.ssh/config に以下のように2つのGitHub接続情報を記述する
# GitHub #1
Host github-corp1
AddKeysToAgent yes
IdentityFile ~/.ssh/github_corp1.privatekey
HostName github.com
User git
IdentitiesOnly yes
# GitHub #2
Host github-corp2
AddKeysToAgent yes
IdentityFile ~/.ssh/github_corp2.privatekey
HostName github.com
User git
IdentitiesOnly yes
【2】git clone する時に、一部書き換えて clone
$ git clone git@github-corp2:hoge/fuga.git
【おまけ】 : 【2】の書き換えがどうしても面倒なら~/.zshrc に以下を追記
これなら $gcl1 githubからのコピペそのまま でクローン可能
# GitHub #1 (Host: github-corp1) 用のクローン関数
function gcl1() {
local modified_url=${1/git@github.com:/git@github-corp1:}
git clone "$modified_url"
}
# GitHub #2 (Host: github-corp2) 用のクローン関数
function gcl2() {
local modified_url=${1/git@github.com:/git@github-corp2:}
git clone "$modified_url"
}
