Created
July 11, 2012 14:24
-
-
Save Sanne/3090687 to your computer and use it in GitHub Desktop.
git-deep-prune
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Script to loop on local and remote branches, to delete all those which are | |
# already merged in master. | |
# Assumes "origin" and "master" are your references: replace all occurrences | |
# of "origin" with the name of your personal remote. | |
# | |
# Careful with branches which should are meant as tags in the past! | |
# | |
# Inspired from http://devblog.springest.com/a-script-to-remove-old-git-branches | |
# Released under the WTFPL license version 2 http://sam.zoy.org/wtfpl/ | |
# Copyright (c) 2012 Sanne Grinovero | |
# Prune stale references to remote, and fetch information on new branches: | |
git fetch --all --prune | |
# Delete local branches which are merged in master | |
git branch --merged master | grep -v 'master$' | xargs git branch -D | |
# Remove remote fully merged branches | |
git branch -r --merged master | grep "origin/" | grep -v "origin/master" | sed -e 's/\s*origin\///' | xargs -I% git push origin :% |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment