ディレクトリの位置はmacを想定しています、個人の備忘録・記事を書く練習の殴り描きです。
調べてたどり着いた方は記事末の参考を参考にしてください。
まず二つのgithubアカウントにて別のssh設定で接続。
~/ssh./config にて
Host github.com-for-private
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa_github_private
TCPKeepAlive yes
IdentitiesOnly yes
この Host の値が
"プロジェクトフォルダ"/.git/config の
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
ignorecase = true
precomposeunicode = true
[remote "origin"]
url = git@github.com-for-private:sample.git
fetch = +refs/heads/*:refs/remotes/origin/*
[branch "main"]
remote = origin
merge = refs/heads/main
[branch "feat/create_question_list"]
remote = origin
merge = refs/heads/feat/create_question_list
[user]
email = sample@gmail.com
git clone や git remote add の時、リポジトリ名の指定を git@github.com:account/sample.git のようにすると思いますが、 これを github.com-for-company:account/sample.git のように指定することで 使用するsslのキー(==GitHubアカウント)を指定することができます。
~.git/configは
cd Project/develop
$ git config --local user.name "sumple_name"
$ git config --local user.email "sumple.gmail"
この具合でもう一つの分も操作します
このようにして個別のプロジェクトで別のssh接続が別のアカウントに繋がるようにします
参考
同一端末で、複数のGitHubアカウントを使い分ける方法
https://github.com/youkinjoh/TrainingWebSocket/wiki/同一端末で、複数のGitHubアカウントを使い分ける方法
複数のgitアカウントを使い分ける
https://qiita.com/0084ken/items/f4a8b0fbff135a987fea
[Git]これだけ押さえる!gitconfigの基本
https://qiita.com/C_HERO/items/c35e679f0b03a5f06469