Skip to content

Instantly share code, notes, and snippets.

@asutherland
Created March 14, 2014 17:48
Show Gist options
  • Save asutherland/9552957 to your computer and use it in GitHub Desktop.
Save asutherland/9552957 to your computer and use it in GitHub Desktop.
modified naive git cleanup script proposed by @millermedeiros
#!/bin/bash
MAYBEECHO=
if [ "$1" != 'gogogo' ]; then
MAYBEECHO=echo
echo "Pretending; pass 'gogogo' as an argument to actually do it."
echo
fi
git branch --merged origin/master | grep -v " master" | xargs -n 1 $MAYBEECHO git branch -d
@millermedeiros
Copy link

just updated my .gitconfig:

[alias]
    ; delete all merged branches
    dm = "!git branch --merged master | grep -v 'master' | xargs -n 1 git branch -d"

so now I run git dm to delete all branches merged into master... it's a dangerous command since I'm not sure if there is an easy way to recover the branches (deletion doesn't show up on reflog), and if commit is merged it won't show up as a detached commit... but I don't think that it's a big deal, can probably just grep the log and find the SHA of the branch merge.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment