cloning with different ssh key from github

Developer from somewhere

I needed to do a git clone using a different key than my own. This was what I had to do to get it to work:

  • in ~/.ssh/config , I setup the following:
Host github-work
  HostName github.com
  IdentityFile /path/to/the/private_key
  User the_github_username
  • add the key to the ssh-agent:
ssh-add /path/to/private/key
  • export GIT_SSH_COMMAND:
export GIT_SSH_COMMAND="ssh -i /path/to/the/private_key"
  • the actual clone:
git clone git@github-work:organization_name/repo.git

This StackOverflow answer helped me with this.