skip to Main Content

My goal is to make the global git config name and email empty. I can do that, but after a while it gets reset to an old email I don’t use anymore.
I’m not sure why or how my /home/<user>/.gitconfig changes, but it does without my awareness.

I’m on Ubuntu 18.04, git 2.17.1.

Does anyone know how I can find what is changing my global config file and/or how I can prevent it from changing?

My global config settings if it’s of any help (how I want it to be). Notice how the [user] group is empty:

[core]
        editor = nano
        pager = less -x1,5
[push]
        default = simple
[merge]
        tool = meld
[mergetool "meld"]
        path = /usr/bin/meld
[mergetool]
        prompt = false
[alias]
        adog2 = log --graph --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(bold green)(%ar$
        adog = log --graph --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(bold cyan)%aD%C($
        co = checkout
        s = status
        u = reset HEAD --
        last = log -1 HEAD
        st = status
        unstage = reset
[user]

This is how it becomes after a while (the name and email values are not real in this example):

[core]
        editor = nano
        pager = less -x1,5
[push]
        default = simple
[merge]
        tool = meld
[mergetool "meld"]
        path = /usr/bin/meld
[mergetool]
        prompt = false
[alias]
        adog2 = log --graph --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(bold green)(%ar$
        adog = log --graph --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(bold cyan)%aD%C($
        co = checkout
        s = status
        u = reset HEAD --
        last = log -1 HEAD
        st = status
        unstage = reset
[user]
        name = Some Fake Name
        email = [email protected]

And before anyone asks, I remove my global git config name and email so that when I clone new repos git asks explicitly for a user and email for that repo. This helps me to manage work and personal git accounts.

3

Answers


  1. Chosen as BEST ANSWER

    I managed to find the cause by setting up auditctl to monitor my global gitconfig file.

    I set up -w /home/<user>/.gitconfig -p rwa -k gitconfig as a rule and read the logs with ausearch -k gitconfig --format text. Then I noticed this:

    At 13:30:35 25/07/2022 <user> successfully opened-file /home/<user>/.gitconfig using /usr/share/atom/resources/app.asar.unpacked/node_modules/dugite/git/bin/git.

    Then I successfully managed to reproduce this. Every time I opened a repository with Atom, Atom rewrote my global .gitconfig file.

    It turns out the problem was Atom's github integration: https://github.com/atom/github/issues/2557. And that got solved in https://github.com/atom/github/pull/2587. I upgraded Atom to 1.60.0 and it fixed the issue.

    Thanks @torek, for informing me this wasn't an expected behavior in my platform. And thanks @jthill, for giving me the idea to monitor the files changes.


  2. Git does not automatically change the .gitconfig file unless you use the git config tool with the --global option to change it explicitly. It’s possible that you’re using an editor with a Git integration or some sort of other tool that modifies this value for you, but we have no way of knowing what that is, and it’s not Git.

    You’d probably want to check what tools you’re using with your Git repository and see if any of them have this feature, and then modify it not to set that value.

    Login or Signup to reply.
  3. You can deny yourself write access to the file, chmod a-w ~/.gitconfig and watch what breaks.

    If whatever’s doing this breaks silently or is doing move replacement you get to set up an inotify watch,

    ( inotifywait -e modify ~/.gitconfig & inotifywait -me moved_to ~ | grep gitconfig ) 
    | while read; do notify-send "$REPLY"; done &
    

    might be enough.

    Calling this behavior "objectionable" feels too mild.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search