7

I'm trying to alias the command:

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

Taken from this answer

This is my .gitconfig file:

[credential]
    helper = wincred
[user]
    name = Doron Grinzaig
    email = doron@doNotSpamMe.Suckers
[push]
    default = simple
[alias]
    db = git branch --merged | grep -v "\*" | grep -v master | grep -v dev | xargs -n 1 git branch -d
    unstage = reset HEAD --

But now when I try to edit the .gitconfig file I get the error:

$ git config --global --edit
fatal: bad config file line 9 in C:\Users\Doron Grinzaig/.gitconfig

I was told I need to use ! for running bash scripts as git alias, but the following returned the same error:

[alias]
    db = !git branch --merged | grep -v "\*" | grep -v master | grep -v dev | xargs -n 1 git branch -d

I'm using git bash for windows.

James Monger
  • 10,181
  • 7
  • 62
  • 98
gdoron
  • 147,333
  • 58
  • 291
  • 367
  • The "bad config file" error could be here for some other reason : bad EOL marker (`\r\n` instead of `\n`, or the reverse, I don't know what git expects on windows), maybe an unbreakable space somewhere ... Try deleting and re-writing the whole [alias] section. – LeGEC Feb 03 '16 at 08:46

1 Answers1

11

Try escaping the quotes and backslash in the first grep command:

[alias]
    db = !git branch --merged | grep -v \"\\*\" | grep -v master | grep -v dev | xargs -n 1 git branch -d
Gary McLean Hall
  • 984
  • 7
  • 16
  • 1
    Can be simplified a bit: `db = !"git branch --merged | grep -vE 'main|master|\\*' | xargs -n 1 git branch -D"` – slm Oct 07 '21 at 01:06