Skip to content

GitHub

Many open source projects host their repository on GitHub.

On 2018-10-26 it was announced that Microsoft had completed their acquisition of GitHub.

Sometimes a developer will need to push commits using a different GitHub account. This could be because the other account belongs to a different organisation. It can be achieved by using a ssh host alias.

A ssh key uniquely identifies a GitHub account.

First create a new ssh key for your non-default GitHub user. Use the ssh-keygen command to create a keypair, and save it an appropriate name. e.g. For an organisation called foo, run

Terminal window
ssh-keygen -f ~/.ssh/id_rsa_foo

Edit your SSH config file, found in ~/.ssh/config and append an entry for the GitHub organisation.

~/.ssh/config
Host foo.github.com
HostName github.com
IdentityFile ~/.ssh/id_rsa_foo

In the above config, foo.github.com is the SSH host pattern. If this host is used, ssh will connect to github.com using the private key found in ~/.ssh/id_rsa_foo.

Login to your GitHub user that is part to the foo organisation.

Navigate to Profile -> Settings -> SSH and GPG Keys -> New SSH key

Fill in

  • Title: my_ssh_key
  • Key Type: Authentication Key
  • Key: Copy and paste the contents from ~/.ssh/id_rsa_foo.pub.

The click on Add SSH key

Copy the repo URL as you would normally do to clone it, but instead of git@github.com, use git@foo.github.com

For this repo, update the default username and email.

Terminal window
git config user.email foo@example.com
Terminal window
git config user.name "example user"