git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 1/3] var: add GIT_HOSTNAME

From
ICIsabella Caselli <bellacaselli20@gmail.com>
Date
Oct 12, 2026, 01:58 UTC
Message-ID
<20261012015846.2649843-2-bellacaselli20@gmail.com>
In-Reply-To
<20261012015846.2649843-1-bellacaselli20@gmail.com>

Git asks the system for the name of the machine it runs on in a few places. For example, "git gc" records it in "gc.pid" to tell whether the gc holding the lock runs on the same machine. Users have no way to see which name Git uses, and depending on how the system is configured, it may be a short name ("myhost") or a fully qualified one ("myhost.example.com").

This matters more once the config can depend on the hostname, which a later commit adds as an includeIf condition. Without a way to see the value Git uses, users would have to guess what to write in their config file.

Add a GIT_HOSTNAME variable to "git var" that prints the hostname Git sees. If the hostname can't be determined, "git var GIT_HOSTNAME" exits with a non-zero status, and "git var -l" omits the variable instead of failing.

An option to "git config" to show the hostname was also discussed, but "git var" was chosen, since the hostname is not specific to the configuration code.

The test only checks that a non-empty value is printed. The test has no independent way to know the expected hostname, as the "hostname" command may not agree with what Git sees on every platform. The includeIf tests added later check that the value matches what the configuration code uses.

Suggested-by: Eric Sunshine <sunshine@sunshineco.com>
Suggested-by: Jeff King <peff@peff.net>
Signed-off-by: Isabella Caselli <bellacaselli20@gmail.com>
---
 Documentation/git-var.adoc |  3 +++
 builtin/var.c              | 13 +++++++++++++
 t/t0007-git-var.sh         |  5 +++++
 3 files changed, 21 insertions(+)
diff --git a/Documentation/git-var.adoc b/Documentation/git-var.adoc
index 697c10aded..e813ab4fd2 100644
--- a/Documentation/git-var.adoc
+++ b/Documentation/git-var.adoc
@@ -84,6 +84,9 @@ endif::git-default-pager[]
 `GIT_CONFIG_GLOBAL`::
     The path to the global (per-user) configuration files, if any.
 
+`GIT_HOSTNAME`::
+    The hostname of the machine, as reported by the operating system.
+
 Most path values contain only one value. However, some can contain multiple
 values, which are separated by newlines, and are listed in order from highest to
 lowest priority.  Callers should be prepared for any such path value to contain
diff --git a/builtin/var.c b/builtin/var.c
index cc3a43cde2..b427ebd61e 100644
--- a/builtin/var.c
+++ b/builtin/var.c
@@ -115,6 +115,15 @@ static char *git_config_val_global(int ident_flag UNUSED)
 	return strbuf_detach(&buf, &unused);
 }
 
+static char *hostname(int ident_flag UNUSED)
+{
+	char buf[HOST_NAME_MAX + 1];
+
+	if (xgethostname(buf, sizeof(buf)))
+		return NULL;
+	return xstrdup(buf);
+}
+
 struct git_var {
 	const char *name;
 	char *(*read)(int);
@@ -166,6 +175,10 @@ static struct git_var git_vars[] = {
 		.read = git_config_val_global,
 		.multivalued = 1,
 	},
+	{
+		.name = "GIT_HOSTNAME",
+		.read = hostname,
+	},
 	{
 		.name = "",
 		.read = NULL,
diff --git a/t/t0007-git-var.sh b/t/t0007-git-var.sh
index 2b60317758..f50c62a25e 100755
--- a/t/t0007-git-var.sh
+++ b/t/t0007-git-var.sh
@@ -224,6 +224,11 @@ test_expect_success 'GIT_CONFIG_GLOBAL points to the correct location' '
 	)
 '
 
+test_expect_success 'GIT_HOSTNAME is not empty' '
+	hostname=$(git var GIT_HOSTNAME) &&
+	test -n "$hostname"
+'
+
 # For git var -l, we check only a representative variable;
 # testing the whole output would make our test too brittle with
 # respect to unrelated changes in the test suite's environment.
-- 
2.43.0
Previous: Isabella CaselliNext: Isabella Caselli
Message 8 of 14 in “hostname: includeIf condition — anyone already working on this?”
  1. Isabella CaselliSep 28, 2026
  2. Jeff KingSep 29, 2026
  3. Ignacio EncinasSep 29, 2026
  4. Jeff KingSep 29, 2026
  5. Junio C HamanoSep 29, 2026
  6. Isabella CaselliOct 2, 2026
  7. 0/3 Add hostname condition to includeIfIsabella Caselli, Oct 12, 2026
  8. 1/3 var: add GIT_HOSTNAMEIsabella Caselli, Oct 12, 2026
  9. 2/3 t6500: get hostname from "git var"Isabella Caselli, Oct 12, 2026
  10. Junio C HamanoOct 12, 2026
  11. Isabella CaselliOct 13, 2026
  12. Junio C HamanoOct 13, 2026
  13. 3/3 config: learn the "hostname:" includeIf conditionIsabella Caselli, Oct 12, 2026
  14. Junio C HamanoOct 12, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.