gdoron
gdoron

Reputation: 150263

How to alias in git delete merged branches

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 = [email protected]
[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.

Upvotes: 7

Views: 2103

Answers (1)

Gary McLean Hall
Gary McLean Hall

Reputation: 994

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

Upvotes: 12

Related Questions