LoginSignup
0
0

More than 3 years have passed since last update.

複数のGItHubアカウントを一つのPC(gitbash)で扱う方法

Last updated at Posted at 2021-02-27

前提条件

  • 既にメインのGitHubを持っていて、gitbashと連携している
  • 新しいGitHubアカウントがすでにある(ない場合は作成してから)
  • 既にあるGItHubアカウントをGit-old、新しいGItHubアカウントをGit-newと呼ぶことにする

ファイルの確認

 1.Git-oldで使っているssh鍵の場所の確認

gitbash
$ cd ~/.ssh
$ ls -l
id_rsa  id_rsa.pub  => Git-oldのssh鍵

 2.Git-newのssh鍵を作成するフォルダ(フォルダ名を任意にaaaに入れて使用)の作成

gitbash
$ mkdir ~/.ssh/aaa

Git-newのssh鍵を作成

gitbash
$ ssh-keygen -t rsa -b 4096 -C {Githubメールアドレス} -f ~/.shh/xxx/id_rsa

鍵の確認

gitbash
$ ls ~/.ssh/aaa/
id_rsa  id_rsa.pub  => Git-newのssh鍵

作成したssh鍵をGItHubに登録

gitbash
$ clip < ~/.ssh/aaa/id_rsa.pub

コピーしたものをGItHubのssh kyesに貼りつけ登録

~/.ssh/configを作成

configファイルがなかったら作成

gitbash
$ touch ~/.ssh/config

configファイルを編集

~/.ssh/config
Host github.com-old
  HostName github.com
  User git
  Port 22
  IdentityFile ~/.ssh/id_rsa
  TCPKeepAlive yes
  IdentitiesOnly yes
Host github.com-new
  HostName github.com
  User git
  Port 22
  IdentityFile ~/.ssh/aaa/id_rsa
  TCPKeepAlive yes
  IdentitiesOnly yes

Hostの部分は自由に変えてください。あとで使います。

sshの接続確認

gitbash
$ ssh -T git@{configファイルのHostの部分}
Hi {GitHubの名前}! You've successfully authenticated, but GitHub does not provide shell access. => 成功

Git-newにpushする方法

pushしたいディレクトリで行うこと

gitbash
$ git init

$ git remote add origin git@{configファイルのHostの部分}:{GitHubの名前}/{リモートリポジトリの名前}.git

$ git add -A && git commit -m "xxx" && git push origin master
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