Skip to content

Instantly share code, notes, and snippets.

@manojkarthick
Last active November 12, 2020 16:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save manojkarthick/45def3b83d8777ab94e6eb024b59dc47 to your computer and use it in GitHub Desktop.
Save manojkarthick/45def3b83d8777ab94e6eb024b59dc47 to your computer and use it in GitHub Desktop.
Git user management

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'"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment