0

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?

Anubian Noob
  • 13,426
  • 6
  • 53
  • 75

1 Answers1

1

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 '

Frederic Henri
  • 51,761
  • 10
  • 113
  • 139
  • Thank you! This works. I guess git aliases are being run on Bash or something? Also, to add this as an alias, you'd do `git config --global alias.branches "!git remote show origin | grep \w*\s*'(new^|tracked)' -E` – Anubian Noob Jul 10 '15 at 14:53
  • right, I am not sure how it is done for windows but for *nix users like, you would update the .gitconfig file directly and update the [alias] section – Frederic Henri Jul 10 '15 at 14:56
  • Git has built in support to directly add an alias: `git config --global alias.[name] "[alias]"` But yeah you can also manually edit the `.gitconfig` file. – Anubian Noob Jul 10 '15 at 15:01