When working with multiple Git repositories — especially private ones — you often find yourself juggling SSH keys. Your local environment might be configured for long-term projects, and setting up permanent access to a one-time repository can be overkill.
Instead of modifying your global SSH config, use the GIT_SSH_COMMAND
environment variable to tell Git which key to use for a specific operation.
Example
Let’s say you have a separate key ~/.ssh/deploy_key
for a private repo. To clone it without touching your SSH config:
GIT_SSH_COMMAND="ssh -i ~/.ssh/deploy_key" git clone git@github.com:username/private-repo.git


When It’s Useful
- In CI/CD pipelines that need SSH access to private repos.
- When managing multiple identities on a single machine (e.g., personal, corporate, freelance).
- For temporary access to third-party repositories.