Skip to content

Commit eced436

Browse files
committed
Add demmer's git-prune-branches script
1 parent 2130d52 commit eced436

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ git clone this repository, then add it to your `$PATH`. Nothing here actually re
110110
* git-object-deflate - Ryan Tomayko's [dotfiles](https://github.com/rtomayko/dotfiles)
111111
* git-outgoing - Michael Markert's [dotfiles](https://github.com/cofi/dotfiles)
112112
* git-promote - Trevor's [Improving My git Workflow](http://hoth.entp.com/2008/11/10/improving-my-git-workflow) blog post
113+
* git-prune-branches - Michael Demmer in [jut-io/git-scripts](https://github.com/jut-io/git-scripts/blob/master/bin/git-prune-branches)
113114
* git-publish - Michael Markert's [dotfiles](https://github.com/cofi/dotfiles)
114115
* git-purge-from-history - David Underhill’s [blog](http://dound.com/2009/04/git-forever-remove-files-or-folders-from-history/)
115116
* git-rank-contributors - William Morgan <wmorgan-git-wt-add@masanjin.net>

git-prune-branches

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/bin/sh
2+
#
3+
# git-prune-branches
4+
#
5+
# Simple script that cleans up unnecessary branches.
6+
#
7+
# First it deletes each fully merged branch after prompting
8+
# for confirmation.
9+
#
10+
# Then it prunes all branches that no longer exist at each upstream
11+
# remote.
12+
13+
merged=`git branch --no-color --merged master | grep -v master | sed 's/\*/ /'`
14+
15+
if [ ! -z "$merged" ] ; then
16+
echo "Deleting the following merged branches:"
17+
for branch in $merged ; do
18+
echo " " $branch
19+
done
20+
21+
all=n
22+
delete=n
23+
for branch in $merged ; do
24+
if [ $all = 'n' ] ; then
25+
delete=n
26+
read -p "Delete $branch (y=yes, n=no, a=all)? " prompt
27+
echo "all=$all delete=$delete prompt=$prompt"
28+
if [ "$prompt" = 'a' ] ; then
29+
delete=y
30+
all=y
31+
elif [ "$prompt" = 'y' ]; then
32+
delete=y
33+
fi
34+
fi
35+
36+
if [ "$delete" = 'y' ] ; then
37+
git branch -d $branch
38+
fi
39+
done
40+
fi
41+
42+
remotes=`git remote`
43+
for remote in $remotes ; do
44+
prompt=n
45+
read -p "Prune deleted branches from remote '$remote' (y=yes n=no)? " prompt
46+
if [ "$prompt" = 'y' ] ; then
47+
git remote prune $remote
48+
fi
49+
done

0 commit comments

Comments
 (0)