Created
April 6, 2021 10:12
-
-
Save lbt/195b6232cc32f81f5722380503d98cdb to your computer and use it in GitHub Desktop.
Change git identity
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
In your config add sections for user-$IDENTITY. Below I use -work and -home | |
Also add an alias to run a script when you want to change .. I chose "user" ... "become" might be fun... | |
$ cat ~/.gitconfig | |
<---------snip----------> | |
[user] | |
name = David Greaves | |
email = david.greaves@jolla.com | |
[user-home] | |
name = David Greaves | |
email = david@dgreaves.com | |
[user-work] | |
name = David Greaves | |
email = david.greaves@jolla.com | |
[alias] | |
user = !/home/david/.gitconfig.d/change_user.sh | |
<---------snip----------> | |
Then add this script (and make it executable): | |
mkdir -p ~/.gitconfig.d | |
cat <<EOF > ~/.gitconfig.d/change_user.sh | |
#!/bin/bash | |
src=$1 | |
if [[ $src == "" ]]; then | |
# Who am I? | |
git config --global --get user.name | |
git config --global --get user.email | |
else | |
# Alter ego... | |
git config --global user.name "$(git config --global user-${src}.name)" | |
git config --global user.email "$(git config --global user-${src}.email)" | |
fi | |
EOF | |
chmod +x ~/.gitconfig.d/change_user.sh |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment