Search code examples
gitaliasgit-config

Git alias for clearing old branches is failing.. why?


Ive made a new git alias to clear out all my old unused git branches but its crashing my git config when i add it? I don't see why since it worked in my bash when i put it in earlier. Or I thought it did anyway!

clean-unused = "!git branch --merged | egrep -v "(^\*|develop)" | xargs git branch -d"

Ive added the ! before the first git command as I understand this will open a new shell to run the command in.

What seems to be the problem here?

The crashing message from git: fatal: bad config line 11 in file /Users/<userName>/.gitconfig


Solution

  • Escape inner double quotes and backslashes:

    clean-unused = "!git branch --merged | egrep -v \"(^\\*|develop)\" | xargs git branch -d"
    

    Just tested, works for me.