Gitの設定確認
グローバル設定(すべてのリポジトリに共通する設定)
git config --global user.name
git config --global user.email
ローカル設定(現在のリポジトリだけに適用)
git config user.name
git config user.email
GitHubへのSSH接続時にどの鍵が使われているか確認する
下記でgithub.comに公開鍵を提示して、その鍵がどのユーザーに紐づいているかをGitHub側がおしえてくれる
ssh -T git@github.com
Hi GitHubアカウント名! You’ve successfully authenticated, but GitHub does not provide shell access.
- 提示した公開鍵からのアカウント名を確認
- シェルコマンドを打つ場所は提供してない
※当然ですが、ls や cd を打って何か作業ができるような環境ではなくて、あくまでGit操作専用ということ
git config user.name
git config user.email
主な設定手順
- サブアカウント用のSSH鍵を生成
cd ~/.ssh
ssh-keygen -f id_rsa_private
- .ssh/configファイルの設定
Host github.com
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa
Host github.private
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa_private
- gitconfigの設定
# ~/.gitconfig_private
[user]
name = サブアカウント名
email = サブアカウントのメール
# ~/.gitconfig に追加
[includeIf "gitdir:~/private/"]
path = ~/.gitconfig_private
- 接続確認
ssh -T github.private
- リモートリポジトリの追加
git remote add origin github.private:username/repo.git
この設定により、~/private/
ディレクトリ以下では自動的にサブアカウントが使用されます。
https://zenn.dev/taichifukumoto/articles/how-to-use-multiple-github-accounts