Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Easy way to have 2 GitHub profiles on my computer?

Tags:

git

github

ssh

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?

like image 798
Jordan Poulton Avatar asked Nov 01 '22 11:11

Jordan Poulton


2 Answers

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.

like image 181
Tux Avatar answered Nov 09 '22 07:11

Tux


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.

like image 30
VonC Avatar answered Nov 09 '22 06:11

VonC