Skip to content

Instantly share code, notes, and snippets.

tomdl89 / auto-stage-untracked-file.el
Last active Dec 10, 2020
Magit to stage (intent-to-add only) untracked files on save
View auto-stage-untracked-file.el
(defun auto-stage-untracked-file ()
"Add an empty version of the currently-visited file to the index
iff it is in a git repo, but untracked."
(when (and (magit-git-dir)
(not (magit-file-tracked-p (buffer-file-name)))
this-command ; nil for auto-save
(y-or-n-p "Add (intent-to-add) file to git index?"))
(magit-run-git "add" "--intent-to-add" "--" (buffer-file-name))))
(add-hook 'after-save-hook 'auto-stage-untracked-file)