I'm a bit a bit stumped by an annoying problem that I'm having with magit. I'm working in a monorepo (lerna) repository that uses husky to run a precommit hook. The hook runs on packages that have changed within the monorepo. When I try to commit using magit, I get an abort message:

  1 git … commit --
starting precommit
yarn run v1.22.5
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
husky - pre-commit hook exited with code 1 (error)

However, if I run a commit command at the command line, there's no abort. I've been trying to debug this but am quite stumped. Why would the behavior change within magit if magit just runs a commit command. Is magit doing something else on top of this? Is there a general incompatibility of some sort with husky or hooks?

Has anyone experienced something similar or have any ideas about how to get better insight into what's going on?

One of the reasons it has been hard to debug is that magit also seems to swallow the output of the precommit script itself, which if I run at the command line I can see. So I know that the linting tests for example are not producing any errors that might causes an exit code designed to abort the commit.

  • 1
    One possibility is environmental difference, e.g. version differences. Try doing the commit on the command line, but from an emacs shell: that may (or may not) show any differences. What does the pre-commit hook look like? Can Check versions of everything that it runs.
    – NickD
    Commented Jan 7, 2023 at 1:01
  • Thanks you @NickD, your idea of running a command from within emacs helped me figure out the problem. I ran the command in the recommit hook using magit-shell-command and was eventually able to spot an error related to an environment variable that is set in my .zshrc but not in the emacs environment. So it's nos just a matter of finding the right way to set that variable for emacs.
    – fraxture
    Commented Jan 7, 2023 at 22:06

1 Answer 1


The problem in my case was that there was an environment variable required by the recommit hook that was set in my normal shell environment but not within the environment that magit runs commands from within emacs.

I figured this out eventually by running different versions of the yarn lerna run... command within emacs using magit-shell-command that is in my pre-commit hook. Eventually, I spotted an error complaining about the missing environment variable.

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.