Skip to content

Instantly share code, notes, and snippets.

@mhaylock
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mhaylock/b7b83911d779f4b351da to your computer and use it in GitHub Desktop.
Save mhaylock/b7b83911d779f4b351da to your computer and use it in GitHub Desktop.
Cleaning up old branches from a Git repo
# Update local remote refs, and delete all local remote refs that have been
# deleted on Github:
$ git fetch -p
# Switch to a primary branch (i.e. 'api' or 'master'), you will use this branch
# to find all merged branches that you will delete:
$ git checkout api
# Find all branches that have been merged with this branch, and delete them.
# NOTE: This might result in your master branch being deleted when run from
# another branch already merged with master. This may or may not be a bad thing
# for you - be aware and decide if you want to avoid that (note that you can
# easily re-checkout the master branch to match your remote):
$ git branch --merged | grep -v "\*" | xargs -n 1 git branch -d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment