3

I'm having some problems with my global git config. Both username and email is set to blank automatically. I can't figure out if there is a pattern to this behaviour, but more often than not git tells me to set username and email when I'm trying to make a commit. Updating using git config --global or directly editing my .gitconfig file both works, but after some time they disappear again.

File content before reset:

[user]
    name = <name>
    email = <email>
[core]
    editor = atom --wait
    excludesfile = /Users/christian/.gitignore_global
[pull]
    rebase = false

File content after reset:

[user]
    name = 
    email = 
[core]
    editor = atom --wait
    excludesfile = /Users/christian/.gitignore_global
[pull]
    rebase = false
  • 4
    Since `git config --global` works by writing to your global `.gitconfig` file, anything else that *destroys* that file (or sets it back to some old contents) would undo the setting. Look for things that change files. Having your home directory on some sort of file-sharing / web-synchronizing service would do it, for instance, as would login startup commands that erase and reset all configuration. – torek Dec 22 '20 at 01:29
  • 2
    You are not losing your mind, I've got exactly the same problem on my Mac (11.0.1) where the `name =` and `email =` values are vanishing from the `[user]` section of my `.gitconfig`. Curiously the `signingkey = xxxxx` is untouched, as is the rest of the file. – Brendon Whateley Jan 21 '21 at 18:01
  • Are you using Atom? I'm having the same problem and I'm suspicious that Atom might be to blame but I'm still investigating – Isaac Betesh Jan 26 '21 at 23:56
  • @IsaacBetesh I am indeed using atom, but not for any interactions with git. I do all that in Terminal. – Christian Olsen Jan 28 '21 at 00:02
  • @IsaacBetesh I am also using Atom and experienced this issue today for the first time. Any ideas? What made you suspicious about Atom? – David S. Jan 28 '21 at 11:14
  • 1
    My suspicions were correct. This is caused by toggling between 2 tabs in Atom, if they contain files from different repos. Closing a tab, if it results in a tab from another repo becoming active, would also cause this. This has already been reported to atom: https://github.com/atom/github/issues/2558 – Isaac Betesh Jan 28 '21 at 20:23

2 Answers2

2

As confirmed by Isaac Betesh this is an Atom problem, where some interactions with tabs from different repositories wipe out the global user/email config. The issue is at: https://github.com/atom/github/issues/2558

I've temporarily worked around the problem by removing the write permission from ~/.gitconfig

Brendon Whateley
  • 1,302
  • 13
  • 22
0

In addition of checking what could delete your ~/.gitconfig global Git configuration, check also if git config user.useConfigOnly is set to true.

Since Git 2.8, that would also force you to set your user.name/email for each repository.

You would also see the effect of that configuration in the error message:

no name was given and auto-detection is disabled
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

If not, then it is back to check if, when you have the issue, your global .gitconfig is deleted or somehow changed/reset.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • user.useConfigOnly is **not** set in my config. It's also only the `[user]` part of my `~/.gitconfig` that is reset. Have a `[core]` section, which is always untouched. – Christian Olsen Dec 23 '20 at 01:59
  • @ChristianOlsen Is that ~/.gitconfig deleted when you have to update your user.name/email? – VonC Dec 23 '20 at 08:44
  • @ChristianOlsen Was the file modified then, when your user.name/email went missing? – VonC Dec 24 '20 at 00:07
  • 1
    Yes! It just happened again. Checking `ls -lc ~/.gitconfig`, I can see it was changed. Any tips on how I can track down the process responsible? – Christian Olsen Dec 27 '20 at 04:45
  • @ChristianOlsen What is its content when it is changed? – VonC Dec 27 '20 at 12:33
  • updated my original post with file content. – Christian Olsen Dec 29 '20 at 02:28
  • @ChristianOlsen sothe values are reset to . Is there any `GIT_xxx` user variable set or unset at any point (as in https://git-scm.com/book/en/v2/Git-Internals-Environment-Variables#_committing) – VonC Dec 29 '20 at 02:38
  • I'm not setting any of those variables at any point. Generally I'm just using standard git commands, e.g. `git status`, `git add`, `git commit`, `git restore` etc. – Christian Olsen Dec 31 '20 at 19:20