diff --git a/Library/Homebrew/brew.sh b/Library/Homebrew/brew.sh
index 1882894732..44896624f9 100644
--- a/Library/Homebrew/brew.sh
+++ b/Library/Homebrew/brew.sh
@@ -794,6 +794,12 @@ fi
source "${HOMEBREW_LIBRARY}/Homebrew/utils/analytics.sh"
setup-analytics
+# Use this configuration file instead of ~/.ssh/config when fetching git over SSH.
+if [[ -n "${HOMEBREW_SSH_CONFIG_PATH}" ]]
+then
+ export GIT_SSH_COMMAND="ssh -F${HOMEBREW_SSH_CONFIG_PATH}"
+fi
+
if [[ -n "${HOMEBREW_BASH_COMMAND}" ]]
then
# source rather than executing directly to ensure the entire file is read into
diff --git a/Library/Homebrew/cmd/update.sh b/Library/Homebrew/cmd/update.sh
index c689c4d24e..876f9880b6 100644
--- a/Library/Homebrew/cmd/update.sh
+++ b/Library/Homebrew/cmd/update.sh
@@ -455,7 +455,7 @@ EOS
fi
export GIT_TERMINAL_PROMPT="0"
- export GIT_SSH_COMMAND="ssh -oBatchMode=yes"
+ export GIT_SSH_COMMAND="${GIT_SSH_COMMAND:-ssh} -oBatchMode=yes"
if [[ -n "${HOMEBREW_GIT_NAME}" ]]
then
diff --git a/Library/Homebrew/env_config.rb b/Library/Homebrew/env_config.rb
index e7b1bb941a..60d3345cee 100644
--- a/Library/Homebrew/env_config.rb
+++ b/Library/Homebrew/env_config.rb
@@ -282,6 +282,11 @@ module Homebrew
description: "If set, running Homebrew on Linux will use homebrew-core instead of linuxbrew-core.",
boolean: true,
},
+ HOMEBREW_SSH_CONFIG_PATH: {
+ description: "If set, Homebrew will use the given config file instead of `~/.ssh/config` when fetching " \
+ "`git` repos over `ssh`.",
+ default_text: "`$HOME/.ssh/config`",
+ },
HOMEBREW_SKIP_OR_LATER_BOTTLES: {
description: "If set along with `HOMEBREW_DEVELOPER`, do not use bottles from older versions " \
"of macOS. This is useful in development on new macOS versions.",
diff --git a/docs/Manpage.md b/docs/Manpage.md
index e786e86694..0e61a1ac1a 100644
--- a/docs/Manpage.md
+++ b/docs/Manpage.md
@@ -2086,6 +2086,11 @@ example, run `export HOMEBREW_NO_INSECURE_REDIRECT=1` rather than just
- `HOMEBREW_FORCE_HOMEBREW_CORE_REPO_ON_LINUX`
If set, running Homebrew on Linux will use homebrew-core instead of linuxbrew-core.
+- `HOMEBREW_SSH_CONFIG_PATH`
+
If set, Homebrew will use the given config file instead of `~/.ssh/config` when fetching `git` repos over `ssh`.
+
+ *Default:* `$HOME/.ssh/config`
+
- `HOMEBREW_SKIP_OR_LATER_BOTTLES`
If set along with `HOMEBREW_DEVELOPER`, do not use bottles from older versions of macOS. This is useful in development on new macOS versions.
diff --git a/manpages/brew.1 b/manpages/brew.1
index a0adb91da9..ba81fbd0a1 100644
--- a/manpages/brew.1
+++ b/manpages/brew.1
@@ -3038,6 +3038,15 @@ If set, running Homebrew on Linux will simulate certain macOS code paths\. This
If set, running Homebrew on Linux will use homebrew\-core instead of linuxbrew\-core\.
.
.TP
+\fBHOMEBREW_SSH_CONFIG_PATH\fR
+.
+.br
+If set, Homebrew will use the given config file instead of \fB~/\.ssh/config\fR when fetching \fBgit\fR repos over \fBssh\fR\.
+.
+.IP
+\fIDefault:\fR \fB$HOME/\.ssh/config\fR
+.
+.TP
\fBHOMEBREW_SKIP_OR_LATER_BOTTLES\fR
.
.br