Search code examples
gitterminalcredentials

git config --list has two entries for user.name


I don't know how I've ended up at this stage but on my Mac, using the terminal, if I enter git config --list, I obtain

credential.helper=osxkeychain
init.defaultbranch=main
user.email=username1@gmail.com
user.name=username1
.
.
.
remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
user.name=username2

Why are there two user.name entries and how do I remove username2? The source of this problem was trying to set up two GitHub credentials, one for work (username1) and one for personal (username2).

If I try git config user.name "username1", then I get

credential.helper=osxkeychain
init.defaultbranch=main
user.email=username1@gmail.com
user.name=username1
.
.
.
remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
user.name=username1

which is better but there's still two entries!


Solution

  • I suspect you have one name in your global git config (not on my mac, but may be ~/.gitconfig) and another in the repo config. Personally, I'd just edit whichever of the two config files you want gone using git config -e with or without --global

    Haven't used github recently, but I assume it is like other sites. For ssh, the authentication name goes in the repo url - user@host/repo.