Charles L. Charles L. - 1 year ago 97
Git Question

Make a git alias to remove all local merged branches

I have a command to delete local copies of branches that have been merged into develop:

git for-each-ref --format='%(refname:short)' refs/heads/ | grep -v develop | xargs -L1 -I '{}' sh -c "git merge-base --is-ancestor {} develop && git branch -d {}"

I'd like to add an alias to my
but I cannot get one to work - I think I'm messing up the escaping. How can I get this command working, or a command that accomplishes the same thing?

Answer Source

Regarding how to create an alias for a compound command or script, this should do:

  branch-clear = !git for-each-ref ... | ...

Or via a function:

  branch-clear = "!f() { git for-each-ref ... | ...; }; f"
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download