LoginSignup
0
0

More than 3 years have passed since last update.

【Mac】gitで複数の鍵・アカウントをconfigファイルで管理する方法

Last updated at Posted at 2019-07-17

案件が複数、githubアカウントも複数で困っている方向け

1、~/.ssh/configファイルを作成する

configファイルを下記の様に記載。
※Hostや秘密鍵の部分は自分の環境で合わせてください。

~/.ssh/config
#プロジェクトAはgithubアカウントA
Host projectA
HostName github.com
User git
Port 22
#↓名前は超適当
IdentityFile ~/.ssh/github_a_rsa
TCPKeepAlive yes
IdentitiesOnly yes

#プロジェクトBはgithubアカウントB
Host projectB
HostName github.com
User git
Port 22
#↓名前は超適当
IdentityFile ~/.ssh/github_b_rsa
TCPKeepAlive yes
IdentitiesOnly yes

2、各プロジェクトのリモートリポジトリURLをメモする。

git@github.com:AccountA/projectA.git
git@github.com:AccountB/projectB.git

3、各プロジェクトの.gitファイルと同じ階層で下記コマンドをそれぞれ実施

ターミナル上での操作
#プロジェクトAの.gitと同階層で実行
$git remote add origin git@projectA:AccountA/projectA.git

#プロジェクトBの.gitと同階層で実行
$git remote add origin git@projectB:AccountB/projectB.git

これで無限にプロジェクト設定できますね。
後は、pullなりpushなりお好きにどうぞm(__)m

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