Can I perhaps add a hook via local variables in the file header?

2 Answers 2


Here is what I use to auto-commit files in 2 directories (for my notes):

(defun egh:maybe-git-auto-commit-mode ()
  (let* ((bfn (buffer-file-name))
         (root (and bfn (vc-git-root bfn)))
         (full-root (and root (expand-file-name root))))
    (if (or (string-equal full-root "/home/egh/c/notes/h/")
            (string-equal full-root "/home/egh/c/notes/w/"))
        (git-auto-commit-mode +1))))
(add-hook 'org-mode-hook #'egh:maybe-git-auto-commit-mode)
(setq-default gac-automatically-push-p t)

This will commit org files when the git root is /home/egh/c/notes/{c,w}.


With this project you can do it easily per-file or per-directory.

If you’re using Emacs 24 or newer you should set an eval file-local variable:

;; -*- eval: (git-auto-commit-mode 1) -*-

If you’re using an older version of Emacs, that should be:

;; -*- mode: git-auto-commit -*-

See https://github.com/ryuslash/git-auto-commit-mode

Your Answer

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

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