Dan Brubaker Horst

I type for a living

Stage All Deleted Files In A Git Repository

by Dan Brubaker Horst

Sometimes I use rm instead of git rm to delete files in a git repository. This simple mistake means that the deleted files are not staged when I try to commit my changes.

A short post on how to use xargs I found this morning led me to a simple solution:

git ls-files -d | xargs git rm

How does this work?

Each deleted file as identified by git ls-files gets converted to git rm FILENAME and then executed.

In the past I had to copy and paste lines out of git status or type out the filenames without the benefit of tab completion in order to stage all the deleted files. I don’t have to do that now. To speed things up even further I added an alias to my dotfiles.