3

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)

Paul Razvan Berg
  • 16,949
  • 9
  • 76
  • 114
  • Possible duplicate of [How to change my Git username in terminal?](https://stackoverflow.com/questions/22844806/how-to-change-my-git-username-in-terminal) – EternalHour Sep 18 '19 at 18:27
  • Make sure you are also updating the repo url. `git remote set-url origin https://username@bitbucket.org/repository.git` – EternalHour Sep 18 '19 at 18:28
  • No, this is not the problem. I'm not trying to update my GitHub user name, rather my author name. – Paul Razvan Berg Sep 18 '19 at 18:32
  • What do you mean when you say it works for a short while? Does it work when you do `git commit`? – unrealsoul007 Sep 18 '19 at 18:37
  • @unrealsoul007 I explained in the question body. "as soon as I open a new terminal window or do a git commit, the old name gets reset" – Paul Razvan Berg Sep 18 '19 at 18:43
  • 2
    It sounds like something in your shell startup scripts are changing it. – William Pursell Sep 18 '19 at 19:17
  • What shell are you using? Does auto-complete work with git? – kelvin Sep 18 '19 at 19:46
  • 1
    Does the `~/.gitconfig` file actually *change?* Does `git config --get user.name` produce a different answer from `git config --global --get user.name`? If `~/.gitconfig` changes, figure out what's changing it, and fix that. If not, but the local and global settings don't match, fix *that*. Also, be sure that you're using `~/.gitconfig` and not `$XDG_CONFIG_HOME/git/config`. – torek Sep 18 '19 at 21:22
  • @kelvin bash. No, auto-complete doesn't work with git. – Paul Razvan Berg Sep 19 '19 at 11:40
  • @torek Yes, `~/.gitconfig` actually *changes*. No, adding the `--global` flag doesn't change the output of `git config --get user.name`. Thanks for your help. – Paul Razvan Berg Sep 19 '19 at 11:41

2 Answers2

4

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
Community
  • 1
  • 1
Greg Bacon
  • 134,834
  • 32
  • 188
  • 245
3

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.

Paul Razvan Berg
  • 16,949
  • 9
  • 76
  • 114