Skip to content

Instantly share code, notes, and snippets.

@tomdl89
Last active December 10, 2020 09:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomdl89/d1c68aac21a66ec656b848503188a491 to your computer and use it in GitHub Desktop.
Save tomdl89/d1c68aac21a66ec656b848503188a491 to your computer and use it in GitHub Desktop.
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