Created
October 21, 2013 13:58
-
-
Save rud/7084313 to your computer and use it in GitHub Desktop.
Simple script for deleting local already merged branches, and prune remote tracking branches where the report part no longer exists. As a practical convenience, it will not delete a few long-lived local branches such as "develop", "master", and "production". This is built on ideas from http://stevenharman.net/git-clean-delete-already-merged-bran…
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/sh | |
# Simple script for pruning local branches already merged, | |
# and remove remote tracking branches that have been deleted | |
# Default to "origin" if no remote is passed | |
remote=${1-origin} | |
# Branches to keep, regardless of their current merge state | |
permanent_branches="develop|master|production" | |
# Remove local already merged branches | |
git branch --merged | grep -v -E "(\*|$permanent_branches)" | xargs -n 1 git branch -d | |
# Retry with whatever 'git remote' outputs | |
git remote prune $remote || git remote prune `git remote` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Suggested addition to
~/.gitconfig
:This assumes the above is available as
prune-git
in$PATH
. Then it can be invoked withgit cleanup-merged
.