Last active
September 14, 2015 23:28
-
-
Save lherich/cbc6dc8488bbede32d99 to your computer and use it in GitHub Desktop.
Replace default git user and email by a specified value for all *.github.com repositories.
This file contains hidden or 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 | |
# | |
# Replace default git user and email by a specified value | |
# for all *.github.com repositories. | |
# | |
# Installation: | |
# 1. Save this script to /usr/local/bin/set-github-user-and-email | |
# 2. Replace PUT_YOUR_NAME_HERE and PUT_YOUR_EMAIL_HERE | |
# 3. chmod 755 /usr/local/bin/set-github-user-and-email | |
# 4. alias git=/usr/local/bin/set-github-user-and-email | |
# | |
# Taken from http://stackoverflow.com/a/13752961 | |
# | |
# "Real" git is the second one returned by 'which' | |
REAL_GIT=$(which -a git | sed -n 2p) | |
# Does the remote "origin" point to GitHub? | |
if ("$REAL_GIT" remote -v 2>/dev/null | | |
grep '^origin\b.*github.com.*(push)$' >/dev/null 2>&1); then | |
# Yes. Set username and email that you use on GitHub. | |
export GIT_AUTHOR_NAME='PUT_YOUR_NAME_HERE' | |
export GIT_AUTHOR_EMAIL='PUT_YOUR_EMAIL_HERE' | |
fi | |
"$REAL_GIT" "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment