I'd recommend making this a bash script in your PATH instead, and then calling that script in your git alias instead (or if it's in your PATH anyway, just name the file git-bd
).
For example, make the file ~/bin/git-bd
#!/usr/bin/env bash
git branch --merged | egrep -v '(^\*|master|dev)' | xargs git branch -d
Make the file executable with the command:
chmod +x ~/bin/git-bd
And make sure your .bashrc
, .bash_profile
or .bash_login
file has the line:
export PATH="$HOME/bin:$PATH"
And you can either just call git-bd
directly, or add the alias in your .gitconfig
like so:
bd = "!git-bd"
To add to this answer, the reason you are getting a bad config error may be due to the back-slashes. The git-config will read them as is, so you need to escape them again with a second backslash.