Skip to content

Instantly share code, notes, and snippets.

@wolfeidau
Created November 13, 2020 04:24
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 wolfeidau/5bf4733d4c0374a0ca0f34ff4af2e41d to your computer and use it in GitHub Desktop.
Save wolfeidau/5bf4733d4c0374a0ca0f34ff4af2e41d to your computer and use it in GitHub Desktop.
Git user switching

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.

To show whoami

git config --global alias.whoami "! git var -l | grep '^GIT_.*_IDENT'"
git whoami
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment