Skip to content

Committing as a Different User

Posted on:June 18, 2021

First create a new SSH key pair to use with your alternate account.

ssh-keygen -t rsa

Add the public key to your alternate account on Github (Settings > SSH and GPG keys).

Once that’s done, add a new entry in your SSH config, usually located in ~/.ssh/config:

Host github.com-something
   HostName github.com
   User git
   IdentityFile ~/.ssh/something

github.com-something is a unique placeholder that SSH will use to resolve the settings to use (in this case, which actual host to connect to, using which private key) — it can be anything you like. Point IdentityFile to the location of the private key of the SSH key pair.

In the .git folder of the project you want to commit to using your alternate account, put the following settings in .git/config:

[user]
        name = My Alternate Account
        email = my_alterate_email@gmail.com
[remote "origin"]
        url = git@github.com-something:githubuser/repo.git
        fetch = +refs/heads/*:refs/remotes/origin/*

Make sure the same github.com-something in the SSH config entry is used as the host in the url field. Tweak the rest of the settings to your liking.

That’s it!