Committing as a Different User

June 18, 2021

First create a new SSH key pair to use with your alter­nate account.

ssh-keygen -t rsa

Add the public key to your alter­nate account on Github (Set­tings > SSH and GPG keys).

Once that’s done, add a new entry in your SSH config, usu­al­ly locat­ed in ~/.ssh/config:

   User git
   IdentityFile ~/.ssh/something is a unique place­hold­er that SSH will use to resolve the set­tings to use (in this case, which actual host to con­nect to, using which pri­vate key) — it can be any­thing you like. Point IdentityFile to the loca­tion of the pri­vate key of the SSH key pair.

In the .git folder of the pro­ject you want to commit to using your alter­nate account, put the fol­low­ing set­tings in .git/config:

        name = My Alternate Account
        email =
[remote "origin"]
        url =
        fetch = +refs/heads/*:refs/remotes/origin/*

Make sure the same in the SSH config entry is used as the host in the url field. Tweak the rest of the set­tings to your liking.

That’s it!