How can I configure different emails for different Git servers or repositories?

“.gitconfig” in your home directory

If you’re like me, and you wanted to configure a different email for different repo’s the first place you look is ~/.gitconfig. This is the default configuration for git for your account. You can set your default user name there, as well as helper apps and other good stuff. But what if you want to change the email or user name for different repositories?

“git config” from the command line

Once you have a local clone of a git repository there is another config file in <my_repo_location>/.git/config. You can edit that manually, or use git to edit it for you…

1
2
3
4
5
6
7
$ cd <my_repo_location>
$ git config user.name "My Name"
$ git config user.email "myemail@sample.com"
$ tail -n 3 .git/config
[user]
    name = My Name
    email = myemail@sample.com

You can also edit the global defaults in a similar way…

1
2
$ git config --global user.name "My Default Name"
$ git config --global user.email "mydefaultemail@default.com"
Category(s): Command Line, Git
Tags: , ,

Leave a Reply

Your email address will not be published. Required fields are marked *

*

 

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Spam protection by WP Captcha-Free