With a secret SSH key:

GIT_SSH_COMMAND="ssh -i $KEY_FILE -F /dev/null -o IdentityAgent=none" 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).

IMPORTANT

If you’re running ssh-agent, then setting the config directive IdentityAgent=none is important as otherwise the key(s) already stored in the agent will take precedence over $KEY_FILE.

With KeePassXC or a GPG authentication subkey referenced using a public $KEY_FILE, setting IdentityAgent=none is unnecessary:

GIT_SSH_COMMAND="ssh -i $KEY_FILE -F /dev/null" git $COMMAND