Bug report: GIT_CONFIG and user.email/name
Hello,
I've faced an issue while trying to use a non-default .gitconfig file via specifyingGIT_CONFIG environment variable.
What did you do before the bug happened? (Steps to reproduce your issue)
```
# use custom .gitconfig via GIT_CONFIG envvar:
mkdir -p /tmp/git-test/repo
cat <<EOT > /tmp/git-test/.gitconfig
[user]
name = John Doe
email = [email protected]
EOT
cd /tmp/git-test/repo
git init
export GIT_CONFIG=/tmp/git-test/.gitconfig
echo Hi > readme.txt
git add readme.txt
git commit -m 'Initial commit'
```What did you expect to happen? (Expected behavior) Git creates a new commit.
What happened instead? (Actual behavior)
Error occurred:
``` Author identity unknown *** Please tell me who you are. Run git config --global user.email "[email protected]" git config --global user.name "Your Name" to set your account's default identity. Omit --global to set the identity only in this repository. fatal: unable to auto-detect email address (got 'john@computer.(none)') ```
What's different between what you expected and what actually happened? For some reason git commit doesn't use configuration options specified in the
custom .gitconfig file.
Anything else you want to add:git config shows correct values:
```
sh-5.1$ pwd
/tmp/git-test/repo
sh-5.1$ echo $GIT_CONFIG
/tmp/git-test/.gitconfig
sh-5.1$ cat $GIT_CONFIG
[user]
name = John Doe
email = [email protected]
sh-5.1$ git config user.name
John Doe
sh-5.1$ git config user.email
[email protected]
```The same happens with git version 2.32.0.432.gabb21c7263
[System Info]
git version:
git version 2.32.0
cpu: x86_64
no commit associated with this build
sizeof-long: 8
sizeof-size_t: 8
shell-path: /bin/sh
uname: Linux 5.12.15-arch1-1 #1 SMP PREEMPT Wed, 07 Jul 2021 23:35:29 +0000 x86_64
compiler info: gnuc: 11.1
libc info: glibc: 2.33
$SHELL (typically, interactive shell): /bin/zsh
Quoted 6 lines · German Lashevich
I've faced an issue while trying to use a non-default .gitconfig file via specifying
GIT_CONFIGenvironment variable.What did you do before the bug happened? (Steps to reproduce your issue)
Quoted 15 lines
```
# use custom .gitconfig via GIT_CONFIG envvar:
mkdir -p /tmp/git-test/repo
cat <<EOT > /tmp/git-test/.gitconfig
[user]
name = John Doe
email = [email protected]
EOT
cd /tmp/git-test/repo
git init
export GIT_CONFIG=/tmp/git-test/.gitconfig
echo Hi > readme.txt
git add readme.txt
git commit -m 'Initial commit'
```The GIT_CONFIG variable doesn't work that way. It is not a general mechanism used by all of Git, but rather a specific feature of the git-config program (and even there it is a historical wart; you should use "git config --file" instead).
One of these variables is probably more helpful:
$ man git | sed -n '/GLOBAL/,/^$/p'
GIT_CONFIG_GLOBAL, GIT_CONFIG_SYSTEM
Take the configuration from the given files instead from global or
system-level configuration files. If GIT_CONFIG_SYSTEM is set, the
system config file defined at build time (usually /etc/gitconfig)
will not be read. Likewise, if GIT_CONFIG_GLOBAL is set, neither
$HOME/.gitconfig nor $XDG_CONFIG_HOME/git/config will be read. Can
be set to /dev/null to skip reading configuration files of the
respective level.Note that they're new in v2.32.0.
-Peff
GIT_CONFIG is confusing, GIT_CONFIG_GLOBAL is what I need.
Thanks a lot!
Quoted 45 lines · Jeff King
Quoted 6 lines · German Lashevich
I've faced an issue while trying to use a non-default .gitconfig file via specifying
GIT_CONFIGenvironment variable.What did you do before the bug happened? (Steps to reproduce your issue)
Quoted 15 lines
``` # use custom .gitconfig via GIT_CONFIG envvar: mkdir -p /tmp/git-test/repo cat <<EOT > /tmp/git-test/.gitconfig [user] name = John Doe email = [email protected] EOT cd /tmp/git-test/repo git init export GIT_CONFIG=/tmp/git-test/.gitconfig echo Hi > readme.txt git add readme.txt git commit -m 'Initial commit' ```The
GIT_CONFIGvariable doesn't work that way. It is not a general mechanism used by all of Git, but rather a specific feature of the git-config program (and even there it is a historical wart; you should use "git config --file" instead).One of these variables is probably more helpful:
$ man git | sed -n '/GLOBAL/,/^$/p' GIT_CONFIG_GLOBAL, GIT_CONFIG_SYSTEM Take the configuration from the given files instead from global or system-level configuration files. If GIT_CONFIG_SYSTEM is set, the system config file defined at build time (usually /etc/gitconfig) will not be read. Likewise, if GIT_CONFIG_GLOBAL is set, neither $HOME/.gitconfig nor $XDG_CONFIG_HOME/git/config will be read. Can be set to /dev/null to skip reading configuration files of the respective level.Note that they're new in v2.32.0.
-Peff
Quoted 4 lines · Jeff King
The
GIT_CONFIGvariable doesn't work that way. It is not a general mechanism used by all of Git, but rather a specific feature of the git-config program (and even there it is a historical wart; you should use "git config --file" instead).
We both have known that, but a fresh re-read of GIT_CONFIG in "git help config" gave me a misleading impression.
ENVIRONMENT
-----------
GIT_CONFIG::
Take the configuration from the given file instead of .git/config. Using the "--global" option forces this to ~/.gitconfig. Using the "--system" option forces this to $(prefix)/etc/gitconfig.
is what we have above the GLOBAL and SYSTEM you quoted below. We should say GIT_CONFIG is only for "git config" command while the other two affects everybody, right?
Thanks.
Quoted 15 lines
One of these variables is probably more helpful:
$ man git | sed -n '/GLOBAL/,/^$/p' GIT_CONFIG_GLOBAL, GIT_CONFIG_SYSTEM Take the configuration from the given files instead from global or system-level configuration files. If GIT_CONFIG_SYSTEM is set, the system config file defined at build time (usually /etc/gitconfig) will not be read. Likewise, if GIT_CONFIG_GLOBAL is set, neither $HOME/.gitconfig nor $XDG_CONFIG_HOME/git/config will be read. Can be set to /dev/null to skip reading configuration files of the respective level.Note that they're new in v2.32.0.
-Peff
Quoted 13 lines · Junio C Hamano
Quoted 4 lines · Jeff King
The
GIT_CONFIGvariable doesn't work that way. It is not a general mechanism used by all of Git, but rather a specific feature of the git-config program (and even there it is a historical wart; you should use "git config --file" instead).We both have known that, but a fresh re-read of
GIT_CONFIGin "git help config" gave me a misleading impression.ENVIRONMENT
-----------
Quoted 8 lines
GIT_CONFIG::
Take the configuration from the given file instead of .git/config. Using the "--global" option forces this to ~/.gitconfig. Using the "--system" option forces this to $(prefix)/etc/gitconfig.is what we have above the GLOBAL and SYSTEM you quoted below. We should say
GIT_CONFIGis only for "git config" command while the other two affects everybody, right?
Yes, it looks like that description is from 2007 (when GIT_CONFIG really did impact other commands). And adding GIT_CONFIG_GLOBAL and SYSTEM nearby certainly didn't help (before then, I might have argued that since GIT_CONFIG is only in git-config(1), it is more clear that it only applies there).
Here's a short series to improve things.
[1/3]: doc/git-config: explain --file instead of referring to GIT_CONFIG [2/3]: doc/git-config: clarify GIT_CONFIG environment variable [3/3]: doc/git-config: simplify "override" advice for FILES section
Documentation/git-config.txt | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-)
-Peff
PATCH 1/3 doc/git-config: explain --file instead of referring to GIT_CONFIG
The explanation for the --file option only refers to GIT_CONFIG. This redirection to an environment variable is confusing, but doubly so because the description of GIT_CONFIG is out of date.
Let's describe --file from scratch, detailing both the reading and writing behavior as we do for other similar options like --system, etc.
---
The formatting is a bit clunky to read in the source, but I think it looks OK in the rendered version. At any rate, it's all taken from the other options, so if we want to improve it, it would make sense to do so separately on top.
Documentation/git-config.txt | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
Documentation/git-config.txt +7 -1
@@ -143,7 +143,13 @@ See also <<FILES>>. -f config-file:: --file config-file:: - Use the given config file instead of the one specified by GIT_CONFIG. + For writing options: write to the specified file rather than the + repository `.git/config`. ++ +For reading options: read only from the specified file rather than from all +avialable files. ++ +See also <<FILES>>. --blob blob:: Similar to `--file` but use the given blob instead of a file. E.g.
Signature · 1 line
2.32.0.689.gbb74d99cdd
Re: [PATCH 1/3] doc/git-config: explain --file instead of referring to GIT_CONFIG
Documentation/git-config.txt See also <<FILES>>. · line 147
Quoted 5 lines · Jeff King
-f config-file::
--file config-file::Documentation/git-config.txt +2
-1- Use the given config file instead of the one specified by GIT_CONFIG. + For writing options: write to the specified file rather than the + repository `.git/config`.
I wonder whether or not we should write "rather than the repository $GIT_DIR/config" instead of .git/config. The former is true for bare repositories, too, but may in fact be more confusing than what you have writen so clearly.
Perhaps .git/config is clear enough; I definitely don't feel strongly about it.
Thanks,
Taylor
Re: [PATCH 1/3] doc/git-config: explain --file instead of referring to GIT_CONFIG
Quoted 12 lines · Taylor Blau
Documentation/git-config.txt See also <<FILES>>. · line 147
Quoted 5 lines · Jeff King
-f config-file::
--file config-file::Documentation/git-config.txt +2
-1- Use the given config file instead of the one specified by GIT_CONFIG. + For writing options: write to the specified file rather than the + repository `.git/config`.I wonder whether or not we should write "rather than the repository
$GIT_DIR/config" instead of.git/config. The former is true for bare repositories, too, but may in fact be more confusing than what you have writen so clearly.
Quoted 2 lines
Perhaps
.git/configis clear enough; I definitely don't feel strongly about it.
Yes, I noticed that, too. This is copied verbatim from the other options, so if we were to do that, it should be done on top across the whole file.
-Peff
Re: [PATCH 1/3] doc/git-config: explain --file instead of referring to GIT_CONFIG
Quoted 7 lines · Jeff King
Quoted 2 lines · Taylor Blau
Perhaps
.git/configis clear enough; I definitely don't feel strongly about it.Yes, I noticed that, too. This is copied verbatim from the other options, so if we were to do that, it should be done on top across the whole file.
I'm dubious that s,.git/config,$GIT_DIR/config,g would be an improvement in clarity if done across the whole file, and I'd rather be consistent than not. So I think that it's fine as is.
Thanks,
Taylor
Re: [PATCH 1/3] doc/git-config: explain --file instead of referring to GIT_CONFIG
In reply to Jeff KingDocumentation/git-config.txt See also <<FILES>>. · line 150
Quoted 6 lines · Jeff King
Documentation/git-config.txt +5
-1- Use the given config file instead of the one specified by GIT_CONFIG. + For writing options: write to the specified file rather than the + repository `.git/config`. ++ +For reading options: read only from the specified file rather than from all +avialable files.
s/avialable/available/
Martin
Re: [PATCH 1/3] doc/git-config: explain --file instead of referring to GIT_CONFIG
Quoted 9 lines · Martin Ågren
Review
Quoted 6 lines · Jeff King
(quoted diff) +5
-1- Use the given config file instead of the one specified by GIT_CONFIG. + For writing options: write to the specified file rather than the + repository `.git/config`. ++ +For reading options: read only from the specified file rather than from all +avialable files.s/avialable/available/
Thanks. You'd think that I would have gotten the part cut-and-paste from earlier right. :)
I double-checked the rest of the series for other spelling errors but didn't see any. This is marked for merging to next, but hasn't made it yet. So if you get this in time, Junio, can you please squash this into the first patch?
Documentation/git-config.txt +1 -1
@@ -147,7 +147,7 @@ See also <<FILES>>. repository `.git/config`. + For reading options: read only from the specified file rather than from all -avialable files. +available files. + See also <<FILES>>.
-Peff
Re: [PATCH 1/3] doc/git-config: explain --file instead of referring to GIT_CONFIG
Quoted 4 lines · Jeff King
I double-checked the rest of the series for other spelling errors but didn't see any. This is marked for merging to next, but hasn't made it yet. So if you get this in time, Junio, can you please squash this into the first patch?
I should say: the first patch of jk/config-env-doc to hopefully make it easier. :)
-Peff
Re: [PATCH 1/3] doc/git-config: explain --file instead of referring to GIT_CONFIG
In reply to Jeff KingQuoted 4 lines · Jeff King
I double-checked the rest of the series for other spelling errors but didn't see any. This is marked for merging to next, but hasn't made it yet. So if you get this in time, Junio, can you please squash this into the first patch?
Thanks, will do.
Quoted 16 lines
Documentation/git-config.txt +1
-2@@ -147,7 +147,7 @@ See also <<FILES>>. repository `.git/config`. + For reading options: read only from the specified file rather than from all -avialable files. +available files. + See also <<FILES>>. -Peff
PATCH 2/3 doc/git-config: clarify GIT_CONFIG environment variable
In reply to Jeff KingThe scope and utility of the GIT_CONFIG variable was drastically reduced by dc87183189 (Only use GIT_CONFIG in "git config", not other programs, 2008-06-30). But the documentation in git-config(1) predates that, which makes it rather misleading.
These days it is really just another way to say "--file". So let's say that, and explicitly make it clear that it does not impact other Git commands (like GIT_CONFIG_SYSTEM, etc, would).
I also bumped it to the bottom of the list of variables, and warned people off of using it. We don't have any plans for deprecation at this point, but there's little point in encouraging people to use it by putting it at the top of the list.
---
I'm taking a more opinionated stance on "nobody should actually use this thing", but I think it's merited. It really is useless, and if not for the history, I'd argue against somebody trying to introduce such a thing now. :)
Documentation/git-config.txt | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)
Documentation/git-config.txt +6 -5
@@ -341,11 +341,6 @@ can specify any filename you want. ENVIRONMENT ----------- -GIT_CONFIG:: - Take the configuration from the given file instead of .git/config. - Using the "--global" option forces this to ~/.gitconfig. Using the - "--system" option forces this to $(prefix)/etc/gitconfig. - GIT_CONFIG_GLOBAL:: GIT_CONFIG_SYSTEM:: Take the configuration from the given files instead from global or
@@ -373,6 +368,12 @@ This is useful for cases where you want to spawn multiple git commands with a common configuration but cannot depend on a configuration file, for example when writing scripts. +GIT_CONFIG:: + If no `--file` option is provided to `git config`, use the file + given by `GIT_CONFIG` as if it were provided via `--file`. This + variable has no effect on other Git commands, and is mostly for + historical compatibility; there is generally no reason to use it + instead of the `--file` option. [[EXAMPLES]] EXAMPLES
Signature · 1 line
2.32.0.689.gbb74d99cdd
PATCH 3/3 doc/git-config: simplify "override" advice for FILES section
In reply to Jeff KingAt the end of the FILES section, we indicate that you can override the regular lookup rules with --global, etc. But:
- we're missing the --local option
- we point to GIT_CONFIG instead of --file, but the latter has much better documentation
- we're vague about how the overrides work; the actual option descriptions are much better here
So let's just mention the names and point people back to the OPTIONS section. We could perhaps even delete this paragraph entirely, but the presence of the names may give people reading FILES a clue about where to look for more information.
--- Documentation/git-config.txt | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
Documentation/git-config.txt +4 -5
@@ -71,6 +71,7 @@ codes are: On success, the command returns the exit code 0. +[[OPTIONS]] OPTIONS -------
@@ -331,11 +332,9 @@ All writing options will per default write to the repository specific configuration file. Note that this also affects options like `--replace-all` and `--unset`. *'git config' will only ever change one file at a time*. -You can override these rules either by command-line options or by environment -variables. The `--global`, `--system` and `--worktree` options will limit -the file used to the global, system-wide or per-worktree file respectively. -The `GIT_CONFIG` environment variable has a similar effect, but you -can specify any filename you want. +You can override these rules using the `--global`, `--system`, +`--local`, `--worktree`, and `--file` command-line options; see +<<OPTIONS>> above. ENVIRONMENT
Signature · 1 line
2.32.0.689.gbb74d99cdd
Taylor Blau
Reviewed-byQuoted 8 lines · Jeff King
Here's a short series to improve things.
[1/3]: doc/git-config: explain --file instead of referring to
GIT_CONFIG[2/3]: doc/git-config: clarifyGIT_CONFIGenvironment variable [3/3]: doc/git-config: simplify "override" advice for FILES sectionDocumentation/git-config.txt | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-)
Looks very good to me. I left a small note on the first patch, but you should feel free to ignore it, since I'm not sure whether my suggestion is an improvement or not ;).
Thanks,
Taylor