Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't change git config's user.name, gets reset immediately

Tags:

git

git-config

If I do:

 git config --global user.name "My New Name"

It works, for a short while. If I do this:

cat ~/.gitconfig

I can see the proper value in the user.name property.

However, as soon as I open a new terminal window or do a git commit, the old name gets reset.

I'm using ssh. Is there some cache mechanism?

(Note this is not about the GitHub username, but rather about the author name for every commit)

like image 336
Paul Razvan Berg Avatar asked Sep 03 '25 05:09

Paul Razvan Berg


2 Answers

The FILES section of the git config documentation shows sources of configuration values.

If not set explicitly with --file, there are four [or five] files where git config will search for configuration options:

  1. $(prefix)/etc/gitconfig
    System-wide configuration file.
  2. $XDG_CONFIG_HOME/git/config
    Second user-specific configuration file. If $XDG_CONFIG_HOME is not set or empty, $HOME/.config/git/config will be used. Any single-valued variable set in this file will be overwritten by whatever is in ~/.gitconfig. It is a good idea not to create this file if you sometimes use older versions of Git, as support for this file was added fairly recently.
  3. ~/.gitconfig
    User-specific configuration file. Also called "global" configuration file.
  4. $GIT_DIR/config
    Repository specific configuration file.
  5. $GIT_DIR/config.worktree
    This is optional and is only searched when extensions.worktreeConfig is present in $GIT_DIR/config.

As to their precedence

The files are read in the order given above, with last value found taking precedence over values read earlier. When multiple values are taken then all values of a key from all files will be used.

In the case where you modify a repository’s config with git config or git config --local (which will modify $GIT_DIR/config, so either .git/config for a repo with a work tree or config in a bare repo), and changes through git config --global (stored in ~/.gitconfig) will be invisible inside that repository.

For a quick sanity check, run two commands.

git config --global user.name
git config --local  user.name
like image 177
Greg Bacon Avatar answered Sep 04 '25 23:09

Greg Bacon


I had a shell script that was overriding the global ~/.gitconfig. Specifically, this .extra file from Mathias Bynens' dotfiles.

See this GitHub issue for more details.

like image 32
Paul Razvan Berg Avatar answered Sep 05 '25 00:09

Paul Razvan Berg



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!