2

I want to create an alias in git git cleanIgnore but I can not figure out how to pipe the output from command 1 to command 2.

I'm using PowerShell and the following command works great from the prompt

git ls-files -i --exclude-from=.gitignore | %{git rm --cached $_}

and I defined this in my global config like this, it doesn't work

[alias]
    cleanIgnore = "!git ls-files -i --exclude-from=.gitignore | %{git rm --cached $_}"
    cleanIgnore2= "!git ls-files -i --exclude-from=.gitignore "

I can get the first half to work as an alias, but I keep getting an error on usage when i do git cleanIgnore

git ls-files -i --exclude-from=.gitignore | %{git rm --cached $_}: %{git: command not found
fatal: While expanding alias 'cleanignore': 'git ls-files -i --exclude-from=.gitignore | %{git rm --cached $_}': No such file or directory

It seems that the ! isn't just passing everything to the shell to execute, but is doing something more still

update/answer

[alias] 
    cleanIgnore = "!powershell.exe -command 'git ls-files -i --exclude-from=.gitignore | %{git rm --cached $_}'"

1 Answer 1

2

another way to create a "new" git command is :

  • create a script named git-cleanIgnore (a powershell script in your case)
  • put this script on your path

regarding the ! alias : I guess git does not execute the command using powershell

you may try to use commmands like xargs (or other linux standard tools, which you could for example install on windows using Cygwin),
or see if you can call something like powershell.exe -command '%{git rm --cached $_}' in your alias

(read the documentation of powershell to see how you can pass a command as an argument to powershell.exe)


[edit] : you found out the way to have your command executed by powershell :

[alias]
    cleanIgnore = "!powershell.exe -command 'git ls-files -i --exclude-from=.gitignore | %{git rm --cached $_}'"
Sign up to request clarification or add additional context in comments.

1 Comment

awesome! if you want to update your reponse with this [alias] cleanIgnore = "!powershell.exe -command 'git ls-files -i --exclude-from=.gitignore | %{git rm --cached $_}'" ill mark this as the accepted answer

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.