Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to specify git email address on the command line?

Tags:

git

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?

like image 638
Noel Yap Avatar asked Jan 14 '23 02:01

Noel Yap


1 Answers

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.

like image 131
Emil Sit Avatar answered Jan 19 '23 12:01

Emil Sit