I'm working with two different Git repositories (ie github and stash) and for each one I want to use a different email address. I know I can use git config
but I don't want to have to remember to do this each time I create a new workspace. So, I'd like to create an alias that sets the email address on the command line. Can this be done?
I suppose I could create a script (as opposed to an alias) that'll git config
, but is there a simpler way to do this?
You can use the following (bash-style) functions:
workgit () {
GIT_COMMITTER_NAME="Work Name" GIT_COMMITTER_EMAIL="[email protected]" GIT_AUTHOR_NAME="Work Name" GIT_AUTHOR_EMAIL="[email protected]" git "$@"
}
homegit () {
GIT_COMMITTER_NAME="Home Name" GIT_COMMITTER_EMAIL="[email protected]" GIT_AUTHOR_NAME="Home Name" GIT_AUTHOR_EMAIL="[email protected]" git "$@"
}
Then you can just call workgit
or homegit
in place of git
to force a given username/e-mail.
This is not an ideal solution (because sometimes you just want to be the committer and not the author, such as when you are rebasing or git am'ing patches) but so long as you are aware of that, you can work around it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With