0

All solutions I've seen so far assume that I want to use a certain key statically. Whereas I want to use a key dynamically: I want to specify what key to use as I run a git command every time. One time I want to be able to use one key, next time -- another.

I've tried this:

# 1
$ git pull origin master -i ~/.ssh/id_ed25519
error: unknown switch `i'
usage: git pull [<options>] [<repository> [<refspec>...]]


# 2
$ git pull -i ~/.ssh/id_ed25519 origin master 
error: unknown switch `i'
usage: git pull [<options>] [<repository> [<refspec>...]]

How can I do this?

6

You can do this using the GIT_SSH_COMMAND environment variable:

GIT_SSH_COMMAND="ssh -i ~/.ssh/id_ed25519" git pull origin master

| improve this answer | |
  • and then I'll have to create a new env. variable if I want to pull from other branch or origin? – Vano Feb 18 '18 at 17:21
  • No, there is no need. The GIT_SSH_COMMAND will be "visible" only for this particular command. – ALex_hha Feb 18 '18 at 19:31
  • that's not working. if I add "-v" to it, it says "debug1: Offering public key: RSA ...." – Vano Feb 20 '18 at 3:34
  • @Vano are you sure you don't have something in your SSH config overriding? Try using GIT_SSH_COMMAND="ssh -F /dev/null -i ~/.ssh/id_ed25519" git pull origin master to ignore any config you have. – Adam Gibbins Feb 24 '18 at 23:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.