git 在 Gitconfig 中设置 GIT_SSH 环境变量

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18047652/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 08:52:19  来源:igfitidea点击:

Set GIT_SSH Environment Variable in Gitconfig

gitgit-config

提问by voltair

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

有没有办法在 gitconfig 文件中设置 GIT_SSH 环境变量?

采纳答案by VonC

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

自从我 2013 年的回答(Git 1.8.3.4)以来,已经设置了一个新的配置:core.sshCommand

If this variable is set, git fetchand git pushwill use the specified command instead of sshwhen they need to connect to a remote system.
The command is in the same form as the GIT_SSH_COMMANDenvironment variable and is overridden when the environment variable is set.

如果这个变量被设置,git fetch并且git push将使用指定的命令而不是ssh当它们需要连接到远程系统时。
该命令与GIT_SSH_COMMAND环境变量的形式相同,并在设置环境变量时被覆盖。

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

它已在Git 2.10 中引入,提交 3c8ede3,2016 年 6 月

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

从那以后,你有了Git 2.13,提交 dd33e077, Feb. 2017,它有ssh.variant

Depending on the value of the environment variables GIT_SSHor 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.variantcan be set to override this auto-detection; valid values are ssh, plink, puttyor tortoiseplink.
Any other value will be treated as normal ssh. This setting can be overridden via the environment variable GIT_SSH_VARIANT.

根据环境变量GIT_SSH或的值GIT_SSH_COMMAND,或配置设置core.sshCommand,Git 自动检测是否调整其命令行参数以用于 plink 或 tortoiseplink,而不是默认值 (OpenSSH)。

ssh.variant可以设置配置变量来覆盖此自动检测;有效值为sshplinkputtytortoiseplink
任何其他值都将被视为正常的 ssh。可以通过环境变量覆盖此设置GIT_SSH_VARIANT



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

对于那些,我需要使用 Git for Windows 附带的 SSH 客户端

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

因此,对于需要 ssh 而不是 putty 的存储库,您可以使用这两种设置在您的配置中准确设置您想要的内容。

 cd /path/to/my/repo
 git config ssh.variant ssh

回答by VonC

GIT_SSHisn't mentioned in the git configman page.

GIT_SSHgit config手册页中没有提到。

"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.

使用 GIT_SSH 错误使用自定义 SSH 的 Git 克隆”描述了如何将选项传递给GIT_SSH,但说明它不是 git repo 配置的一部分。