I found this user management strategy somewhere, and it's been working great for me:
git config --global --unset user.name
git config --global --unset user.email
git config --global --unset user.signingkey
git config --global user.useConfigOnly true
git config --global user.<id>.name "<name>"
git config --global user.<id>.email "<email>"
git config --global alias.identity '! git config user.name "$(git config user.$1.name)"; git config user.email "$(git config user.$1.email)"; :'
- So given that I have created two users, e.g. personal and work I run:
git identity work
- In repos that need the work name/e-mail, and
git identity personal
in the ones that are private. - Whoami configuration:
git config --global alias.whoami = "! git var -l | grep '^GIT_.*_IDENT'"