To set up specific SSH keys for specific git repositories there is the possibility to leverage an SSH config feature.
Given:
- your private key is ~/.ssh/special_id_rsa
- the SSH git repo “URI” git@github.com:username/reponame.git
You can setup/modify the ~/.ssh/config like this:
Host your.hostname.com
Hostname github.com
User git
IdentityFile ~/.ssh/special_id_rsa
When you clone the repo use the following URL instead:
git clone git@your.hostname.com:username/reponame.git
In case the repo has been already cloned/initiated you got to modify .git/config:
[remote "origin"]
url = git@your.hostname.com:username/reponame.git
Reference: