DevWL
DevWL

Reputation: 18840

Adding ALIAS to GIT config for a set of commands

I have a problem adding an alias to my git config for this set of commands.

git ls-files --deleted -z | xargs -0 git rm

I tried this:

git config --global alias.rmd "ls-files --deleted -z | xargs -0 git rm"

When I run git rmd this would prompt me with a missing parameter for ls-files. Is the alias syntax incorrect or perhaps there is a typo somewhere ... ?

Upvotes: 2

Views: 262

Answers (1)

Rob Bajorek
Rob Bajorek

Reputation: 6560

The pipe is messing up the alias. You can do what you want by adding !git to the beginning of your alias.

Try:

git config --global alias.rmd '!git ls-files --deleted -z | xargs -0 git rm'

Note that I replaced your " quotes with ' to stop the ! from being expanded.

In your git config, you should now have the following:

[alias]
    rmd = !git ls-files --deleted -z | xargs -0 git rm

Technically, ! means "run in the shell as-is", so you that's why you need to add git at the beginning of your command line. The cool thing about ! is you can start an alias with something other than git if you like.

Upvotes: 4

Related Questions