Git Reference ยท Environment Variables
GIT_SSH_COMMAND
Reference for GIT_SSH_COMMAND, GIT_SSH, core.sshCommand and ssh.variant: pick a key, port or wrapper for Git's ssh transport and debug what Git passes to ssh.
When a remote URL uses ssh (ssh://host/path or the scp-like user@host:path), Git does not speak ssh itself. It starts an external program, normally ssh, and talks to git-upload-pack or git-receive-pack through it. GIT_SSH_COMMAND replaces that program and lets you add options such as a specific identity file.
The value is a shell command line, so it may contain arguments and quoting. Git appends its own options (port, user and host, the remote command) after yours.
GIT_SSH_COMMAND="ssh -i ~/.ssh/deploy_key -o IdentitiesOnly=yes" git fetch git config core.sshCommand "ssh -F ~/.ssh/config.work" # same idea, stored in config
Try it
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.
Syntax
GIT_SSH_COMMAND='<command line>' git <command> GIT_SSH=<program> git <command> git config core.sshCommand '<command line>' git config ssh.variant <auto|ssh|simple|plink|putty|tortoiseplink>
| Name | Description |
|---|---|
GIT_SSH_COMMAND |
Shell command line used instead of ssh. Arguments allowed. |
GIT_SSH |
Path to a single program (no arguments). Called as program [-p port] host command. Older and less flexible. |
core.sshCommand |
Configuration equivalent of GIT_SSH_COMMAND, useful per repository or with includeIf. |
GIT_SSH_VARIANT / ssh.variant |
Tells Git which option dialect the program understands, so it knows whether -p, -4, -o SendEnv=... are safe to pass. |
Priority: GIT_SSH_COMMAND, then core.sshCommand, then GIT_SSH, then plain ssh from PATH.
Variants: ssh (OpenSSH-compatible, the default guess when the name looks like ssh), simple (only host command, no port or other options), plink, putty and tortoiseplink. Git sniffs the program name; for an unrecognized wrapper it may probe with -G, which is why a script with an odd name can behave unexpectedly. Set ssh.variant to remove the guesswork. With the simple variant, a URL that needs a port fails with an error saying so.
Usage notes
- Per-repository deploy keys:
git config core.sshCommand "ssh -i ~/.ssh/repo_key -o IdentitiesOnly=yes".IdentitiesOnly=yesstops the agent from offering every other key first, which can trigger server-side "too many authentication failures". - Debugging:
GIT_SSH_COMMAND="ssh -vvv" git fetchshows the whole handshake. Combine withGIT_TRACE=1to see the exact command Git runs. - Scp-like URLs (
user@host:path) never carry a port. To use another port, switch tossh://user@host:port/pathor put the host in~/.ssh/config. - The command is run by a shell, so quote paths with spaces carefully and avoid putting untrusted input into the variable.
- Git adds
-o SendEnv=GIT_PROTOCOLfor the OpenSSH variant so servers can negotiate protocol v2; that is the extra option you see in the first example. - Submodules are separate repositories with their own configuration, so an environment variable reaches them but a
core.sshCommandset in the parent's local config does not. - Not used for
https://,git://orfile://remotes.