« Back to home

Mercurial's addremove, now for Git

If you've been raised on mercurial, there are a few commands you just take for granted, "hg addremove" being one of them. Unfortunately, git has no equivalent built in, splitting the adding & removing into two separate commands.

If you're like me, this cannot stand. Nor should it, with a simple alias, set with a single command:

git config --global alias.addremove '!git add . && git ls-files --deleted | xargs git rm'

 

For some reason, entering this command into a Windows command console fails with the standard "you must've fatfingered something" git help output. You need to enter it into the Git Bash console, but once entered, the alias works in the Windows console just fine. Go figure.

A final note: If you run this, and there are no deleted files to remove, you'll get the "git rm" help message. You can ignore it, the add step is clean regardless.