Search code examples
gitbatch-filealiascommand-promptgit-alias

Why doesn't this git alias to find remote branches work?


I'm on Windows Command Prompt (don't judge).

I have this command:

git remote show origin | grep \w*\s*(new^|tracked) -E

This works fine, printing what I expect:

    dev                                  tracked
    master                               tracked
    my-account                           tracked
    payment-request                      tracked

I've tried to add it as an alias:

git config --global alias.branches "!git remote show origin | grep \w*\s*(new^|tracked) -E"

My config file looks like this:

alias.branches=!git remote show origin | grep \w*\s*(new^|tracked) -E

But when I run it:

>git branches

git remote show origin | grep \w*\s*(new^|tracked) -E: -c: line 0: syntax error near unexpected token `('
git remote show origin | grep \w*\s*(new^|tracked) -E: -c: line 0: `git remote show origin | grep \w*\s*(new^|tracked) -E'

I don't understand why this is giving this syntax error here, when it worked perfectly fine when I manually ran the command. Why is this error occurring, and how can I fix it?


Solution

  • did you try with

    git remote show origin | grep \w*\s*'(new^|tracked)' -E
    

    in your alias, on linux I have the same error when I run your command and it works when I add the '