DEV Community

Discussion on: A Practical Guide to Managing Multiple Git Accounts with SSH

Collapse
 
anchildress1 profile image
Ashley Childress

This a great overview, thanks! Have you ever worked with the includeIf config option? I've found that it's sometimes easier to work with (although not as streamlined as your approach).

The tradeoff for me is I can work in either my git_work or git_personal directories with the exact same commands. Git handles the context switching for me based on the includeIf setting, which pulls a sub-config file based on the repo's directory location. If you're only supporting two, it's not a terrible setup. I have one common config plus two separate sub-configs each with a different email address, gpgKey, and ssh command (the later really just points to the right ssh key).

Collapse
 
m_s_360 profile image
M_S_360

Hey Ashley. Thanks for the comment.

Yes I did use to combine .gitconfig file with the ssh config file in the past.

  1. ssh config file to actually determine which ssh key to use

  2. .gitconfig file with the includeif setting to configure the git username and email to commit and push the code into respective repo.

BTW I am not sure if you can specify the particular ssh key to use with different git remote URLs, just with the .gitconfig file.
I'd be fascinated to learn if this has changed now tho.

Collapse
 
anchildress1 profile image
Ashley Childress

You may be correct about using it with different remotes. The git config core.sshCommand "ssh -i ~/.ssh/id_rsa_account" I have setup works for the one remote having different accounts.

I'm curious about it now, too! I had to stop myself from going on a treasure hunt knowing I still have about a billion other things that still need to be finished tonight! 😆

Thanks again for the article!