ssh-agent bash -c "ssh-add $KEY_FILE && git $COMMAND"

INFO

$KEY_FILE must be the full path of a private key (e.g., ~/.ssh/id_rsa or ~/.ssh/gpg_auth_key.pub).

This is useful for running multiple, one-off commands. Note that this method won’t work when used with GPG authentication subkeys.