Created
April 5, 2012 09:16
-
-
Save madx/2309422 to your computer and use it in GitHub Desktop.
Managing your identity in Git
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
Install | |
======= | |
# cp git-identity /usr/lib/git-core/ | |
# chmod +x /usr/lib/git-core/git-identity | |
$ git config --global profile.default.name "Your name" | |
$ git config --global profile.default.email "Your email" | |
$ git config --global user.profile default | |
Usage | |
===== | |
Printing the current profile: | |
$ git identity | |
Current profile: user [[email protected]] | |
Changing profile: | |
$ git identity user2 | |
Using profile user2: user2 [[email protected]] | |
Adding a profile: | |
$ git config --global profile.user3.name user3 | |
$ git config --global profile.user3.email [email protected] | |
Deleting a profile: | |
$ git config --global --remove-profile profile.user3 |
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
#!/bin/bash | |
. /usr/lib/git-core/git-sh-setup | |
lookup () { | |
local profile=$1 | |
local key=$2 | |
git config -z profile.$profile.$key | |
} | |
switch_id () { | |
local profile=$1 | |
local name="$(lookup $profile name)" | |
local email="$(lookup $profile email)" | |
echo "Using profile $1: $name [$email]" | |
git config user.profile "$profile" | |
git config user.name "$name" | |
git config user.email "$email" | |
} | |
print_id () { | |
local profile="$(git config user.profile)" | |
echo "Current profile: $(lookup $profile name) [$(lookup $profile email)]" | |
} | |
PROFILE="$1" | |
case $PROFILE in | |
"") | |
print_id | |
;; | |
*) | |
switch_id $PROFILE | |
;; | |
esac |
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
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE | |
Version 2, December 2004 | |
Copyright (C) 2012 François Vaux <[email protected]> | |
Everyone is permitted to copy and distribute verbatim or modified | |
copies of this license document, and changing it is allowed as long | |
as the name is changed. | |
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE | |
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION | |
0. You just DO WHAT THE FUCK YOU WANT TO. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment