I have a personal account and a work account on github, and I want to be able to push and pull to whichever I want.
Github won't let me use the same SSH key for both accounts, so how should I play this?
If I try to generate another SSH key, it either overwrites the old one, or doesn't create a new one - should I just save it, say, to ~/.ssh/id_rsa2 ?
And will I need to change the username and email in my .gitconfig file every time I want to switch users, or could I have multiple users defined in there?
To put it simply, what's the best (or any!) way to manage multiple github accounts from the same machine?
http://mherman.org/blog/2013/09/16/managing-multiple-github-accounts/
This blog post does a great job of detailing a way to manage both accounts.
Basically, you'll create an ssh config file and switch between them with ssh -T <profileName>
You'll need to store the keys in seperate files, however.
The other approach is to use https url, which allows you to specify which account you want to use for a given repo remote url:
git remote set-url origin https://<username>@github.com/<username>/<reponame>
With the netrc credential helper, you can store the password (or access token, if you are using the 2fa) for each account, which allows you to never enter them.
And you can encrypt those passwords too.
Don't forget to set the right user.name
and user.email
for each local clone.
Or you can manage those settings with a script.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With