Skip to content

Instantly share code, notes, and snippets.

@festival4799
Created January 28, 2023 14:56
Show Gist options
  • Select an option

  • Save festival4799/cb0211c2f4439d962a8f730ce4eb14ba to your computer and use it in GitHub Desktop.

Select an option

Save festival4799/cb0211c2f4439d962a8f730ce4eb14ba to your computer and use it in GitHub Desktop.
Multiple identities in gitconfig with alias
#!/bin/bash
# Set the different identities used in your global '~/.gitconfig' file
git config --global user.gitlab.name "Your Name"
git config --global user.gitlab.email "gitlab@example.com"
git config --global user.github.name "Your Name"
git config --global user.github.email "github@example.com"
git config --global user.identity3.name "Your Name"
git config --global user.identity3.email "identity3@example.com"
# Create an alias to setup the identity
git config --global alias.identity '! git config user.name "$(git config user.$1.name)"; git config user.email "$(git config user.$1.email)"; :'
# Now, you can set your local identity with the comand below:
git identity gitlab # Set the gitlab identoty in your local '.git/config' file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment