This post will show you how to set up your computer to use multiple Github accounts on a single computer.
I am assuming you already have a Github account setup properly on your machine. For the sake of this demo let’s call it
Set up an SSH Key
First we’ll need to create and register a new SSH key.
$ cd ~/.ssh $ ssh-keygen -t rsa -C "your-key-name"
I like to name my keys in such way so I don’t forget what they are about. For this demo let’s just name it
Next, add the key to SSH:
$ ssh-add ~/.ssh/second-github-account
Associate the New Key with Github
Now you need to associate this key with Github:
- Go to Github > Settings > SSH keys.
- Add SSH key
- Give it a title. I’d name it
<computer name> <key name>. For example
Macbook Air second-github-account.
- Paste in the public key. You can find this by typing
cat ~/.ssh/second-github-account.pubin your terminal. (Don’t forget the
Create a Config File
In order for Git to be able to distinguish which key it should use for each repo, you’ll need to setup a
$ touch ~/.ssh/config $ subl ~/.ssh/config
In there you’ll need to add your current/default account and the new one we just created:
#Default GitHub Account Host github.com HostName github.com User git IdentityFile ~/.ssh/first-github-account #Second GitHub Account Host github-second HostName github.com User git IdentityFile ~/.ssh/second-github-account
Using the New Github Account with Git
Now, you’ll use git pretty much the same way you are used to. The only thing that is different is the way you refer to your remote repo.
[email protected] come from?
Check out the config file we just created. Under the second account we have
Host github-second and
User git. That’s it!
Now, when you clone a repo or add a remote, the only thing you need to remember is to change
github.com to your