I'm trying to use a .dir_locals.el file to override the author field in Git commits (so when I'm committing something in a work repo, I use my work email).

It looks like magit-commit-arguments is what I need to frob, but I can't seem to get it to work. I've tried the following:

((nil . ((magit-commit-arguments . ("--author John SJ Anderson <john@working.work>")))))

but it doesn't take effect. The variable's local value does get set, but either Magit ignores it, or I get various type mismatch errors from different levels of the Magit code.

(Note: I have a bunch of work repos, and I don't want to set this on an individual repo level in each individual .git/config. I'm also not interested in solutions outside of Emacs; I already have a solution that works from the CLI, but it depends on environment variables and won't easily port to Emacs. I want something that will work, with Magit, inside Emacs.)


@genhack's answer should work fine, but if you care to know the underlying problem and how to fix it, the issue is that the way you write it, the Git process receives a single argument --author John SJ Anderson <john@working.work> whereas when you use the command from the shell you'll typically type it git --author "John SJ Anderson <john@working.work>" ... which results in 2 arguments passed to git: --author and John SJ Anderson <john@working.work>.

In order to pass those 2 arguments, you need to set magit-commit-arguments to ("--author" "John SJ Anderson <john@working.work>").

  • I swear I tried that at one point and it didn't work, but it's possible I had some other syntax issue going on...
    – genehack
    Oct 15 '17 at 0:48

This works:

((nil . ((magit-commit-arguments . ("--author=John SJ Anderson <john@working.works>")))))

(The difference there is the = between --author and the value.)

Magit troubleshooting protip which I just figured out: use the magit-popup buffer to configure the settings you want, save them to your custom settings file with C-x C-s, and then look at what changed in there to figure out how you need to define variables.

  • 1
    You shouldn't need the inner single quotes, I think. Are you not getting the literal quotes in the author name that way?
    – npostavs
    Oct 14 '17 at 19:27
  • yep, it works without the inner single quotes. updated answer to remove them.
    – genehack
    Oct 14 '17 at 20:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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