Skip to content

Instantly share code, notes, and snippets.

@justinhj
Created July 7, 2013 21:28
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save justinhj/5945047 to your computer and use it in GitHub Desktop.
Save justinhj/5945047 to your computer and use it in GitHub Desktop.
Allows you to use dired to add multiple files to a git repository. This is useful since staging files in magit is sluggish and takes a long time when you have a lot of files.
(defun git-add-files(files)
"Run git add with the input file"
(interactive)
(shell-command (format "git add %s" files)))
(defun dired-git-add-marked-files()
"For each marked file in a dired buffer add it to the index"
(interactive)
(if (eq major-mode 'dired-mode)
(let ((filenames (dired-get-marked-files))
(files ""))
(dolist (fn filenames)
(setq fn (shell-quote-argument fn))
(setq files (concat files " " fn)))
(git-add-files files))
(error (format "Not a Dired buffer \(%s\)" major-mode))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment