0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

複数の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

このURLを一部書き換える
image.png

$ 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"
}
0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?