I work on both work and personal projects on my machine, and for my work projects, I prefer to use my work email, and vice versa.

In shell, I use direnv to set GIT_COMMITTER_EMAIL and GIT_AUTHOR_EMAIL.

How do I achieve something like this in magit?

  • 2
    Might be possible to use .dir-locals.el somehow, either modify process-environment or magit-git-global-arguments.
    – npostavs
    Commented Feb 1, 2016 at 10:48
  • i wrote github.com/wbolster/emacs-direnv to integrate direnv with emacs. but see my other answer, there are better options for your specific use case here. Commented Nov 5, 2019 at 14:19

4 Answers 4


One way to do this is to set the author configuration in .git/config in each repository, in the same format as in ~/.gitconfig, i.e.:

    name = My Name
    email = [email protected]
  • 1
    Hmm... The problem with this approach, is that I need to do this in each repo, and I have a lot of work repos. With direnv, I can set this up in the folder that contains all the repos, and it works. Wondering if there is something similar I can do.
    – zsquare
    Commented Feb 1, 2016 at 7:15

you can do this with one-time git configuration. you can use it for email and so on, but also for using a different ssh key:

in ~/.gitconfig:

[includeIf "gitdir:~/work/"]
path = .gitconfig_work

in ~/.gitconfig_work:

email = …

sshCommand = ssh -i ~/.ssh/id_…_work -o 'IdentitiesOnly yes'

explanation: this makes git use another configuration, which specifies email and a ssh key (which you should create with a different filename and then add to your github account) when running git anywhere below the ~/work directory. in practice, this one time configuration makes it work for all current and future clones.


Anoter useful option is the git-identity package.

From its README:

This Emacs package lets you manage local Git identities, i.e. user.name and user.email options in .git/config, inside Emacs. It can be useful if you satisfy all of the following conditions:

- You have multiple Git identities on the same machine(s).
- You use Emacs.
- You (almost always) use magit for Git operations on your machine(s).

Same effective answer as @legoscia, but instead of modifying the file, I find that if you do

git config user.email [email protected]
git config user.name "My Name" 

It sets the local config, i.e .git/config

If you add the flag --global then it modifies your global config.

Thus you can have different name/email setup per repository, and can even check them by running git config user.email. When called without any arguements, it works as a GET command.

  • Added a comment to @legoscia's answer. Same applies here.
    – zsquare
    Commented Feb 1, 2016 at 9:29
  • @zsquare This only needs to be done once, Not sure if there is a parent folder customizability, but it cant be hard to script it into every child of a parent folder
    – Karthik T
    Commented Feb 2, 2016 at 6:59
  • @zsquare perhaps you can look at unix.stackexchange.com/questions/42785/… and specifically the last answer.
    – Karthik T
    Commented Feb 2, 2016 at 7:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.