I’ve gotten into situations were I need to have the work and personal git accounts on the same PC. This is the common setup to avoid the https token mess and use ssh instead.
Generate a key like:
ssh-keygen -t ed25519 -C "your_email@example.com"
Put your email and give it a name (prefer the account name).
Then paste the .pub into your ssh keys list on your github account (“New SSH key”).
Create a .config file in .ssh/ with this config:
Host github.com
HostName github.com
AddKeysToAgent yes
User git
IdentityFile ~/.ssh/your_keyname
Add UseKeychain yes if you are on macOS and do ssh-add --apple-use-keychain ~/.ssh/keyname.
You can edit Host with something related to the account. I recommend not to use the exact git account name. Could be github-work or github-personal. This way you can point to the correct account.
Do the same steps for the other account.
Now you just go respectively to each repository on your local and configure those repos with the correct user and email.
git config user.name "your_username"
git config user.email "username@domain.com"
Finally if you are clonning:
git@github-work:your_username/repo.git
Or change the remote origin url:
git remote set-url origin git@github-work:you_username/repo.git