Skip to content

Instantly share code, notes, and snippets.

@jvahldick
Last active October 30, 2019 09:52
Show Gist options
  • Save jvahldick/e7b56e6e55e475b4b4d0bd9c45233dab to your computer and use it in GitHub Desktop.
Save jvahldick/e7b56e6e55e475b4b4d0bd9c45233dab to your computer and use it in GitHub Desktop.
Place the script on /usr/local/bin/git to change the name and email before executing the git command
#!/usr/bin/env bash
GIT_SCRIPT=$(which -a git | sed -n 2p)
# Does the remote "origin" point to GitHub?
if ("$GIT_SCRIPT" 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='*** username ***'
export GIT_AUTHOR_EMAIL='*** email ***'
fi
# Does the remote "origin" point to BitBucket?
if ("$GIT_SCRIPT" remote -v 2>/dev/null |
grep '^origin\b.*bitbucket.org.*(push)$' >/dev/null 2>&1); then
# Yes. Set username and email that you use on Bitbucket.
export GIT_AUTHOR_NAME='*** username ***'
export GIT_AUTHOR_EMAIL='*** email ***'
fi
"$GIT_SCRIPT" "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment