在 ~/.ssh/config 中添加配置

1
2
3
4
5
Host github.com
HostName github.com
User git
IdentityFile /Users/nbaoping/.ssh/id_rsa.github
IdentitiesOnly yes

使用环境变量 GIT_SSH_COMMAND

1
GIT_SSH_COMMAND="ssh -i ~/.ssh/id_rsa_example" git clone example

在仓库clone时指定key

1
git clone git@github.com:yoyun/hello.git --config core.sshCommand="ssh -i ~/.ssh/you_ssh_key"

在config中指定key

1
git config core.sshCommand "ssh -i ~/.ssh/you_ssh_key"