0

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 = some@fake.email

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.

rayly
  • 41
  • 3
  • As an alternative, you can have repository-specific Git configurations that override your global configuration. – chepner Jul 16 '22 at 12:45
  • 1
    See https://stackoverflow.com/a/32124169/341994 – matt Jul 16 '22 at 12:53
  • @matt: he seems to have some rogue Git installer program that updates his global Git configuration without him asking it to, such that `user.name` and `user.email` become set. I've never seen this myself, and I used Ubuntu 18.04 for several years, so I have no idea what might be doing that. – torek Jul 16 '22 at 13:31
  • @torek Agreed, but we have no way of knowing what that is, nor is it a programming issue; and the linked question results in many, many ways of achieving the desired goal, as well as clues to possible causes of the phenomenon (eg a hook of some sort). So I don't see how the current question is distinguished from the duplicate. – matt Jul 16 '22 at 14:01

3 Answers3

4

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.

jthill
  • 55,082
  • 5
  • 77
  • 137
2

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.

rayly
  • 41
  • 3
0

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.

bk2204
  • 64,793
  • 6
  • 84
  • 100
  • Excellent assessment and critique of the question, but not an _answer_. The question as it stands _cannot_ be answered and isn't really about Git or programming. – matt Jul 16 '22 at 21:24