I was using following answer: https://emacs.stackexchange.com/a/57535/18414 to set markdown on the .git/COMMIT_EDITMSG file.

(add-to-list 'auto-mode-alist
             '("/\\.git/COMMIT_EDITMSG\\'" . markdown-mode))

My .gitconfig file, to open commit message with emacs:

    editor = TERM=xterm-256color emacsclient -t -q

On my emacs-daemon magit-git was enable.

Now during the commit (due to some squash operations in git), I see the commit messag along with the opened magit-diff: window.

Example image:

enter image description here

When I check the major-mode it became Local in buffer COMMIT_EDITMSG; global value is fundamental-mode.

Afterwards, when I added into COMMIT_EDITMSG file and do C-s C-x, commit fails and I get following message:

fatal: could not read commit message: No such file or directory

But instead if I re-enable markdown-mode, save and exit there would be no error.

[Q] Is it possible to force markdown-mode during git commit?

1 Answer 1


You're using a package which is very opinionated about how things with Git should work, so don't be surprised if related Emacs configuration which works without Magit gets clobbered when you do use Magit.

In this instance, Magit uses git-commit.el which provides the variable git-commit-major-mode for controlling this.

If you want to control how things happen in Magit, you want to be checking the Magit documentation firstly.

  • I am little bit lost about how to set markdown-mode under magit-mode-hook, or is it even possible. If I can't accomplish it, my only option is seems like Type C-c C-c to finish, or C-c C-k to cancel
    – alper
    Commented Jul 1, 2020 at 21:01
  • No need to use a hook to set this variable -- it's not buffer-local. Just use the customize link from C-h v git-commit-major-mode, or setq it in your init file.
    – phils
    Commented Jul 1, 2020 at 21:02
  • From customization I only have two options: 0 = text-mode 1= No major mode . I setted to no major mode but didn't help
    – alper
    Commented Jul 1, 2020 at 21:06
  • 1
    Yep, just noticed that myself. That's pretty weird. You'll have to use this in your init file: (setq git-commit-major-mode 'markdown-mode)
    – phils
    Commented Jul 1, 2020 at 21:08
  • 1
    Tangentially, I see that the current version of Magit has fixed that customize issue for git-commit-major-mode (and even includes markdown as a default option). That alone won't change anything else, but I felt it was worth noting.
    – phils
    Commented Jul 1, 2020 at 22:26

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.