18

Is there a way to set the GIT_SSH environment variable in the gitconfig file?

2
  • 1
    What do you want to put into the GIT_SSH variable? Some settings may also be done in ~/.ssh/config instead. Commented Aug 5, 2013 at 13:15
  • 1
    In my case, I usually use PuTTY for handling Git, as it is quite compatible and has a solid SSH agent. However, some Git repos I use have interactive login and PuTTY doesn't handle this. For those, I need to use the SSH client that Git for Windows came with. I'd rather have GIT_SSH set in the config per-repo. Commented Aug 8, 2017 at 18:10

2 Answers 2

9
+100

Since my 2013 answer (Git 1.8.3.4), a new configuration has been set: core.sshCommand

If this variable is set, git fetch and git push will use the specified command instead of ssh when they need to connect to a remote system.
The command is in the same form as the GIT_SSH_COMMAND environment variable and is overridden when the environment variable is set.

It has been introduced in Git 2.10, commit 3c8ede3, June 2016

Since then, you have Git 2.13, commit dd33e077, Feb. 2017, which has ssh.variant

Depending on the value of the environment variables GIT_SSH or GIT_SSH_COMMAND, or the config setting core.sshCommand, Git auto-detects whether to adjust its command-line parameters for use with plink or tortoiseplink, as opposed to the default (OpenSSH).

The config variable ssh.variant can be set to override this auto-detection; valid values are ssh, plink, putty or tortoiseplink.
Any other value will be treated as normal ssh. This setting can be overridden via the environment variable GIT_SSH_VARIANT.


For those, I need to use the SSH client that Git for Windows came with

So for the repos where you need ssh instead of putty, you can use both settings to set exactly in your configuration what you want.

 cd /path/to/my/repo
 git config ssh.variant ssh
Sign up to request clarification or add additional context in comments.

Comments

7

GIT_SSH isn't mentioned in the git config man page.

"Git clone with custom SSH using GIT_SSH error" describes how to pass option to GIT_SSH, but illustrates that it isn't part of a git repo config.

2 Comments

Thanks for your help! Is there any other way to automate setting the GIT-SSH environment variable as gitconfig would if the option existed?
@voltair on unix, it would be in your.profile, or your.bashrc. On Windows, it would be registered in your user environment variables.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.