0

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!

user1936752
  • 756
  • 1
  • 9
  • 25
  • 2
    `--show-origin` option could help understand where the settings come from: https://git-scm.com/docs/git-config#Documentation/git-config.txt---show-origin – Philippe Sep 24 '22 at 21:05

2 Answers2

2

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.

DrC
  • 7,528
  • 1
  • 22
  • 37
  • Thank you - and as a general question, if I add a config file within the repo folder, does that take priority over the config file outside the repo folder? – user1936752 Sep 24 '22 at 19:06
  • 1
    You don't have to add such a file. It exists under .git/config (or just config for bare repos) and holds the values for the repo. Yes, local settings override globals (afaik). – DrC Sep 24 '22 at 19:13
  • 1
    To be precise / pedantic, local configs override global ones for *most* configuration settings, including `user.name` and `user.email`. There are a few settings where the local ones *add on* to the global ones ... but not these two. – torek Sep 25 '22 at 08:45
1

You can unset the name with this command:

git config --unset user.name

And maybe you can find something to be able to create a working and personal environment

Multiple GitHub accounts on the same computer?

Nathan
  • 38
  • 5