Charles L. Charles L. - 2 months ago 5x
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?


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"