Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Magit to stage (intent-to-add only) untracked files on save
(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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment