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

git appears to ignore GIT_CONFIG environment variable

From
SBSirio Balmelli <sirio.bm@gmail.com>
Date
Nov 2, 2018, 01:32 UTC
Message-ID
<3389BCF7-6170-4242-82D3-0FE7FB2EA5F2@gmail.com>
It appears that git ignores the GIT_CONFIG environment variable, while git-config *does* consider it.

I have written a short script that shows this in detail and reproduces, it is included below and also posted on github at https://github.com/siriobalmelli/toolbench/blob/master/git/git-env-check.sh This behavior is confirmed in 2.17.1, 2.18.0 and 2.19.1

I have tried to google this but don’t see any references to GIT_CONFIG outside of the git-config manual. Is it intended behavior that this environment variable is only valid with git-config?

Thank you very much,
Sirio
—

#!/bin/bash # this script demonstrates that the GIT_CONFIG is used by 'git-config' # but *not* by 'git' itself. # 2018 Sirio Balmelli

cleanup() { rm -rf ~/.gitconfig git-env-check }

fail()
{
	echo "$*" >&2
	cleanup
	exit 1
}
# don't break the user's config
if [[ -e ~/.gitconfig ]]; then
	# don't fail, deleting ~/.gitconfig, for obvious reasons
	echo "this script would break your existing ~/.gitconfig - please remove it and run again" >&2
	exit 1
fi
unset GIT_CONFIG
git config -l | grep -q alias.he=help \
	&& fail "alias 'he' already set, can't use it for this test" \
	|| echo "1. the alias 'he' is unset by default"
echo "2. write a gitconfig in a non-standard location; export to GIT_CONFIG:"
mkdir git-env-check
cat <<EOF | tee git-env-check/gitconfig
[alias]
  he = help
EOF
export GIT_CONFIG=$(realpath git-env-check/gitconfig)
env | grep GIT_CONFIG
git config -l | grep -q alias.he=help \
	|| fail "unexpected: git-config doesn't see GIT_CONFIG" \
	&& echo "3. git-config DID see 'he' from GIT_CONFIG"
git he \
	&& fail "git does see GIT_CONFIG: please ignore this report" \
	|| echo "4. git, however, did NOT see 'he'"
ln -s $GIT_CONFIG ~/.gitconfig
git he >/dev/null \
	|| fail "unexpected: git also ignores ~/.gitconfig" \
	&& echo "5. git DOES see 'he' if conf is linked to '~/.gitconfig'"

echo "6. this was $(git --version)" cleanup

Next: Junio C Hamano
Message 1 of 3 in “git appears to ignore GIT_CONFIG environment variable”
  1. Sirio BalmelliNov 2, 2018
  2. Junio C HamanoNov 2, 2018
  3. Sirio BalmelliNov 3, 2018

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.