0

I'm looking to translate this little bash function I have saved as the git tidy alias to either PowerShell or cmd, so that it can be used across my Windows Terminal in both Windows and Linux Subsystem.

git branch --merged | grep -v \"\\*\" | xargs -n 1 git branch -d;

The script itself is detects any branches in the current git repo that have been merged into the currently checked-out branch (git branch --merged), filters all branches not currently checked-out (| grep -v \"\\*\"), and deletes them locally (| xargs -n 1 git branch -d).

Obviously executing this command in something like PowerShell or cmd raises the error 'grep' is not recognized .... I don't know enough PowerShell or cmd scripting to be able to translate this command for use on either of the Windows shells.

What would the equivalent of the above command be for PowerShell and/or cmd?

torek
  • 448,244
  • 59
  • 642
  • 775
Medallyon
  • 110
  • 1
  • 1
  • 15
  • Use Select-String with a Pattern (uses Regex instead of LEX [grep]) : https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/select-string?force_isolation=true&view=powershell-7.2 – jdweng Oct 26 '22 at 16:34
  • Does this answer your question? [Remove tracking branches no longer on remote](https://stackoverflow.com/questions/7726949/remove-tracking-branches-no-longer-on-remote) – GreenGrassTunnel Oct 27 '22 at 07:01
  • I actually just stumbled across this: [Run Linux tools from a Windows command line](https://learn.microsoft.com/en-us/windows/wsl/filesystems#run-linux-tools-from-a-windows-command-line). Seeing as I make use of WSL, I'm able to call `wsl git tidy` from my Windows Terminal. Furthermore, I'm able to make use of this as the git alias on my Windows portion - `git config --global alias.tidy "!wsl git tidy"`. – Medallyon Oct 27 '22 at 14:59
  • obviously `grep` can be run from any shells including cmd and powershell, if the executable is found in the `PATH` environment variable. And `grep -v \"\\*\"` is wrong, why on earth do you want to match the quotes? – phuclv Oct 27 '22 at 16:08

0 Answers0