Specifying Specific SSH Keys for Git Remotes

Written in 2012. Versions, commands and links may well be out of date.

When using Git via SSH with services such as GitHub and Gitorious, it can be useful to use specific / different ssh keys than your default. This is accomplished with an entry such as the following in your ~/.ssh/config:

Host some-alias
    IdentityFile /home/username/.ssh/id_rsa-some-alias
    IdentitiesOnly yes
    HostName git.example.com
    User git

You then specify this remote as follows in .git/config:

url = some-alias:project/repository.git