Skip to content

Instantly share code, notes, and snippets.

@9z0b3t1c
Created April 24, 2012 13:45
Show Gist options
  • Save 9z0b3t1c/2479777 to your computer and use it in GitHub Desktop.
Save 9z0b3t1c/2479777 to your computer and use it in GitHub Desktop.
Clean up git branches
# This has to be run from master
git checkout master
# Update our list of remotes
git fetch
git remote prune origin
# Remove local fully merged branches
git branch --merged master | grep -v master | grep -v am-test | grep -v production | xargs git branch -d
# Take a look at the list of remote branches which haven't been merged into master
git branch -r --merged master | sed 's/ *origin\///' | grep -v master | grep -v production | grep -v am-test
# Remove merged user story branches:
git branch -r --merged master | sed 's/ *origin\///' | grep US* | xargs -I% git push origin :%
# Remove merged defect branches
git branch -r --merged master | sed 's/ *origin\///' | grep DE* | xargs -I% git push origin :%
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment