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.
Create a separate SSH key
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
ssh-keygen -f ~/.ssh/id_rsa_foo
Edit your SSH config file, found in
~/.ssh/config and append an entry for the GitHub organisation.
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
Add the public ssh Key to GitHub
Login to your GitHub user that is part to the
SSH and GPG Keys ->
New SSH key
- Key Type:
- Key: Copy and paste the contents from
The click on
Add SSH key
Cloning a repo
Copy the repo URL as you would normally do to clone it, but instead of
Update the git username and email
For this repo, update the default username and email.
git config user.email email@example.com
git config user.name "example user"