Skip to content

Instantly share code, notes, and snippets.

@bjhomer
Created March 13, 2015 18:15
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save bjhomer/b846af22c2d81d5e5f7e to your computer and use it in GitHub Desktop.
Save bjhomer/b846af22c2d81d5e5f7e to your computer and use it in GitHub Desktop.
A git alias to delete branches whose remote tracking branches are gone
# Drop this into your ~/.gitconfig
[alias]
delete-merged = !bash -c '\
REMOTE=$1 && \
REMOTE=${REMOTE:="origin"} && \
echo "Fetching $REMOTE" && \
git fetch $REMOTE --prune && \
git branch -vv | grep "gone]" | awk \"{ print \\$1 }\" | xargs git branch -d' -
# Run it like so:
# $ git delete-merged origin
#
# If any local branch is tracking a remote branch that has been removed, the local branch will also be removed.
# Note that "origin" is the default parameter, but you can pass your remote name.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment