107

For some reason I'm getting the error that "More than one value for the key user.name" when I try to set the user.name for my git account. How can I set it to a single name?

Nakilon
  • 34,866
  • 14
  • 107
  • 142
tshauck
  • 20,746
  • 8
  • 36
  • 36
  • I think I have a similar problem. But I can't find the answer here. I'm not sure why, and if my question would be duplicated from this one. I wonder if people who answered this question would be willing to clarify the problem. Examining files "local", "global" and "settings" I can see only one `user.name` in global. But `git config --list` and `git config --get-all user.name` gives it twice to me. But `git config --local --get-all user.name` gives none. `git config --global --get-all user.name` gives a single one. `git config --system --get-all user.name` gives none. Strange!? – DrBeco Aug 03 '15 at 00:44
  • Got it! After upgrade, something weird made git consider both, the link and the file, to be a separate thing. I had a `ln ~/.config/git/config ~/.gitconfig` link. Now I deleted the link file `~/.gitconfig`. I've added it some time ago, when git did not looked at `~/.config/` directory, to be more organized. – DrBeco Aug 03 '15 at 00:52
  • 1
    @DrBeco, This error happens when you accidentally run something like `git config user.name foo bar`. – Pacerier Oct 16 '15 at 04:30

10 Answers10

175

If you just want to reset all of them:

git config --global --replace-all user.email "new@mail.com"
mb21
  • 34,845
  • 8
  • 116
  • 142
  • 7
    If there are local repository settings, this won't reset those. Repeat the command without the `--global` flag to reset those: `git config --replace-all user.email "new@mail.com"` – Unixmonkey Jun 17 '14 at 20:48
  • 1
    This is the only answer that answers the question - you are right. It actually removed the duplicating entries thanks @mb21 – Samuel Owino Jun 13 '17 at 12:35
  • 2
    This does not work for me for the 'core.autocrlf' variable. It set the one on the below only. – Devs love ZenUML Jul 18 '17 at 01:44
  • Heh. Keeps adding more and more for me! `$ git --version`, `git version 2.17.2 (Apple Git-113)` – Ashley Coolman Aug 07 '19 at 14:24
72

Update (December 2012)

git1.8.1rc1 now operates differently:

"git config --get" used to diagnose presence of multiple definitions of the same variable in the same configuration file as an error, but it now applies the "last one wins" rule used by the internal configuration logic.

Strictly speaking, this may be an API regression but it is expected that nobody will notice it in practice.


Original answer (November 2010)

The git config man page mentions:

The variable names are case-insensitive and only alphanumeric characters and - are allowed.
There can be more than one value for a given variable; we say then that variable is multivalued.

Actually, such config settings (with multiple possible values) are called multivar

As Jefromi suggests, see in what of the 3 config files you have more than one user.name line.
You can query multiple values like so:

git config --local  --get-all user.name #local repo git config file)
git config --global --get-all user.name #user config file)
git config --system --get-all user.name #system git config file)

The one config file which answers more than one user.name value needs to be fixed.


From the comments:

Examining files "local", "global" and "settings" I can see only one user.name in global.
But git config --list and git config --get-all user.name gives it twice to me

As I mention in here with Git 2.8 (March 2016), you can use (to see all settings:

git config -l --show-origin

One you see where the duplicate setting is (local, global, system), you can use git config [--local/--global/--system] --replace-all key value, as in mb21's answer.

Clement Cherlin
  • 387
  • 6
  • 13
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • 5
    If you have a local repo name overriding a user global name, `git config --get-all user.name` will print both of them, and not tell you which one came from where. That's why I suggested just looking at the files; seems easier than trying to be careful about querying with the command. – Cascabel Nov 30 '10 at 14:37
  • 4
    The question is "How can I set it to a single name?" - I can't see the answer above? – Luke Puplett Dec 17 '12 at 20:11
  • @LukePuplett you can set it to a single name by: a/ changing the different values to the same one at the system, global and local level, or b/ removing extra values, and keeping only one level. Each time, a simple `git config key value` is involved, but you need first to determine the value on each level. That is where my answer comes into the picture. – VonC Dec 17 '12 at 20:17
  • @VonC Something odd is going on in the Windows version. Setting global settings for the diff tool just adds more and more k:v pairs in the .gitconfig file - http://stackoverflow.com/questions/13921687/git-says-more-than-one-value-for-the-key-difftool-vs2012-cmd – Luke Puplett Dec 18 '12 at 18:57
  • This was helpful, using App::Sqitch I got thrown a 'multiple values' error from Config::Gitlike, I just did `sqitch config --replace-all user.name 'new_value'` etc and that fixed it. Thanks! – a7omiton Oct 24 '15 at 19:18
  • I had this problem with Git 2.25.1 on Linux, so it's not just for old versions of Git. The fix was to edit `.git/config` in a repo which had 2 entries for `user.name`. – RichVel Mar 01 '21 at 07:54
  • 1
    @RichVel Good catch. A `git config --show-origin --show-scope --get-all user.name` can help. – VonC Mar 01 '21 at 08:06
  • @VonC - good to know. `--show-scope` didn't work in Git 2.25 but is present in [Git 2.26 onwards](https://github.blog/2020-03-22-highlights-from-git-2-26/) – RichVel Mar 01 '21 at 08:09
  • @RichVel I should have known ;) I documented it last year: https://stackoverflow.com/a/60286340/6309 – VonC Mar 01 '21 at 08:11
13

You should examine the contents of ~/.gitconfig (your user-global config) as well as .git/config in the repository in question (the repo-specific config). You should see two name lines under a user section in one of them. (It could also be two separate user sections in one file.) Just delete the one you don't want, and you should be good to go.

You could also directly set it with git config --global user.name "Desired name" if you want it to be a global setting (probably the case), or the same minus the --global for a repo-specific setting - but it's probably best to inspect the files and find the culprit yourself, to make sure you know what you have. The repo-specific one will override the global one. Ideally you should set your name globally, and only override it in a project for a good reason.

Cascabel
  • 479,068
  • 72
  • 370
  • 318
  • I have observed multiple names in .gitconfig and updated them to single value. And then assigned globally as you mentioned in /etc/bashrc/ It took the new value from global configuration. Thx. – kumar Jan 20 '14 at 07:11
10

To debug such things you may use this command:

git config --list --show-origin

It shows the origin file for each configuration entry.
Example output with duplicated core.autocrlf and unwanted C:\\ProgramData/Git/config file:

$ git config --list --show-origin
file:"C:\\ProgramData/Git/config"       core.symlinks=false
file:"C:\\ProgramData/Git/config"       core.autocrlf=true
file:"C:\\ProgramData/Git/config"       core.fscache=true
file:"C:\\ProgramData/Git/config"       color.diff=auto
file:"C:\\ProgramData/Git/config"       color.status=auto
file:"C:\\ProgramData/Git/config"       color.branch=auto
file:"C:\\Program Files\\Git\\mingw64/etc/gitconfig"    diff.astextplain.textconv=astextplain
file:"C:\\Program Files\\Git\\mingw64/etc/gitconfig"    filter.lfs.clean=git-lfs clean -- %f
file:"C:\\Program Files\\Git\\mingw64/etc/gitconfig"    filter.lfs.smudge=git-lfs smudge -- %f
file:"C:\\Program Files\\Git\\mingw64/etc/gitconfig"    filter.lfs.required=true
file:"C:\\Program Files\\Git\\mingw64/etc/gitconfig"    filter.lfs.process=git-lfs filter-process
file:"C:\\Program Files\\Git\\mingw64/etc/gitconfig"    credential.helper=manager
file:C:/Users/john.doe/.gitconfig   user.name=John Doe
file:C:/Users/john.doe/.gitconfig   user.email=john.doe@somemail.com
file:C:/Users/john.doe/.gitconfig   core.preloadindex=true
file:C:/Users/john.doe/.gitconfig   core.fscache=true
file:C:/Users/john.doe/.gitconfig   core.autocrlf=input
file:C:/Users/john.doe/.gitconfig   gc.auto=256
file:.git/config        core.filemode=false
file:.git/config        core.bare=false
file:.git/config        core.logallrefupdates=true
file:.git/config        core.symlinks=false
file:.git/config        core.ignorecase=true
file:.git/config        core.autocrlf=input

You may do the same with --system and --global to check where your gitconfig files are located:

git config --global --list --show-origin

Example output:

file:C:/Users/john.doe/.gitconfig   user.name=John Doe
file:C:/Users/john.doe/.gitconfig   user.email=john.doe@somemail.com
file:C:/Users/john.doe/.gitconfig   core.preloadindex=true
file:C:/Users/john.doe/.gitconfig   core.fscache=true
file:C:/Users/john.doe/.gitconfig   core.autocrlf=input
file:C:/Users/john.doe/.gitconfig   gc.auto=256
luke
  • 3,435
  • 33
  • 41
7

First look to see what user.names are in the config:

git config --list

Example output:

user.email=abarker@cern.ch
user.name=fiveisgreen
user.github=fiveisgreen
user.name=Anthony

In this example, user.name is listed twice. To remove the duplicate do:

git config --global --unset user.name
sumanchalki
  • 1,457
  • 17
  • 21
Schroeder
  • 742
  • 8
  • 19
7

You can manually change / edit user name and email for github

Go to your application directory

See all hidden files...In that go to .git hidden folder

Open file config file

It will show some lines like

[user]
    name = =
    name = =
    email = =

Replace those line with

[user]
    name = username
    email = user@test.com
Sumit Munot
  • 3,748
  • 1
  • 32
  • 51
2

This thread helped me a great deal. Here is what I did to resolve a duplicate key entry in my global config settings. Windows 7. I searched for a file called .gitconfig which was located in /users/owner on my system. I edited it with a text editor (Atom) and removed the offending line.

I believe the duplicate key was set when I inadvertently enclosed my email address in quotes while using the git config command, at least that's what my shell log indicates. Ooops!

2

Show/Replace/Remove/Add Keys to git config

First check your config as

git config --list

Then if you have multiple values against on key then you have to

#git config --replace-all git_key_name git_key_value
# real example
git config --replace-all credential.helper store

Once you have only one value against a key, the key can be removed as well

#git config --unset git_key_name
# real example
#git config --unset credential.helper

Any time later you can add any key again or new one just by

git config git_key_name git_key_value
Sami
  • 8,168
  • 9
  • 66
  • 99
1

I faced the same issue. Here is how I fixed it.

First, check how many user.name or user.email fields do you have in config: (in my case I had 4 to 5 user.name and user.email fields)

git config --list

Example output:

user.email ==
user.name ==
user.email ==
user.name ==
user.email ==
user.name ==
user.email ==
user.name ==
user.email ==
user.name ==

Now go to your C:\Users[Your PC User Name] and search for the file .gitconfig (It is a hidden file. Make sure to enable view hidden files option).
After finding the file open it. Now remove all the duplicate fields of user.name and user.email.

You can now either set your user.name and user.email with code

git config --global user.name "Ali"
git config --global user.email "Abc@gmail.com"

or either type your user.name= Ali and user.email=abc@gmail.com manually in the .gitconfig file.

Zaid Aly
  • 163
  • 1
  • 17
0

warning: user.name has multiple values

To change the user.name:

git config --global --replace-all user.name Mohammad

To check your Current Username or Email:

git config --global user.name


git config --global user.email