Working parts
- private key for each account
- gitconfig files for each git account
- update .gitconfig to condtionally switch between users
- update ssh config file to use keys, and unique hostname for each user
- update usage -> git remote addresses to match users ssh config
# ~/.gitconfig
#default account
[include]
path = ~/Documents/gitconfigs/git-personal.conf
#second account
[includeIf "gitdir:~/path/to/two/"]
path = ~/Documents/gitconfigs/git-user-2.conf
[filter "lfs"]
clean = git-lfs clean -- %f
smudge = git-lfs smudge -- %f
process = git-lfs filter-process
required = true
#third account
[includeIf "gitdir:/path/to/three/"]
path = ~/Documents/gitconfigs/git-user-3.conf
[filter "lfs"]
clean = git-lfs clean -- %f
smudge = git-lfs smudge -- %f
process = git-lfs filter-process
required = true
# git-work.conf
[user]
name = enter_name
email = enter_email
# ~/.ssh/config
# default
Host github.com
User git
HostName github.com
PreferredAuthentications publickey
IdentityFile /path/to/account/key
# another account 2
# syntax: github.com-[user]
Host github.com-user-2
HostName github.com
User git
PreferredAuthentications publickey
IdentityFile /path/to/second/account/key
# “github.com-user-2” is a notation used to differentiate the multiple Git accounts. You can also use
# “work_user1.github.com” notation as well. Make sure you’re consistent with what hostname notation you use. This is relevant
# when you clone a repository or when you set the remote origin for a local repository
might have to set approiate account key to ssh agent
# delete keys
ssh-add -D
# add appropiate ssh key you need at the time
ssh-add ~/.ssh/id_rsa_user
git clone [email protected]:user-2/repo_name.git
git remote set-url origin [email protected]:user-2/repo_name.git
https://www.freecodecamp.org/news/manage-multiple-github-accounts-the-ssh-way-2dadc30ccaca/