7
7
git_branch_kill () {
8
8
EXEC=" "
9
9
LOCALKILL=-d
10
+ REMOTEKILL=no
10
11
REPODIRS=" "
11
12
12
13
# We do parse some outputs, so keep it single-language
@@ -22,6 +23,7 @@ while [ $# -gt 0 ]; do
22
23
echo " help clean up after a branch has been merged and is no longer used"
23
24
echo " -n Read-only mode to see what might be done"
24
25
echo " -D Allow destruction of un-merged local branches"
26
+ echo " -DD Cause the remote repo(s) to forget named branch(es)"
25
27
echo " -R 'dirs...' List one or more local repositories (directories)"
26
28
echo " to act upon; the parameter may be specified more than once,"
27
29
echo " and its argument may be a space-separated list of directories"
@@ -38,6 +40,10 @@ while [ $# -gt 0 ]; do
38
40
echo " Info: Allowing destruction of un-merged local branches!" >&2
39
41
shift 1
40
42
;;
43
+ -DD) REMOTEKILL=yes
44
+ echo " Info: Pushing destruction of named branches to remotes!" >&2
45
+ shift 1
46
+ ;;
41
47
-R) if [ -n " $2 " ] ; then
42
48
for D in $2 ; do
43
49
if [ -d " $D " ]; then
@@ -108,6 +114,27 @@ L($RES) `pwd` $B `echo ${_OUT} | tr '\n' ' '`"
108
114
fi
109
115
echo " $_OUT "
110
116
fi
117
+
118
+ # Note that you may (try to) remove any branch on a remote server,
119
+ # including your current one or a master one (not all git workflows
120
+ # even use a "master" or assign a special meaning to it).
121
+ if [ " $REMOTEKILL " = yes ]; then
122
+ for R in $REMOTES ; do
123
+ echo " Info: Removing the branch '$B ' in remote repo '$R ' ..."
124
+ _OUT=" ` $EXEC git push " $R " " :$B " 2>&1 ` "
125
+ _RES=$?
126
+ if [ " $_RES " = 0 ] || \
127
+ echo " $_OUT " | egrep " does not appear to be a git repository|remote ref does not exist|Please make sure you have the correct access rights" > /dev/null \
128
+ ; then
129
+ echo " OK, now OTHER clones of this remote repo should 'git fetch --all --prune'"
130
+ else
131
+ RES=$_RES
132
+ [ " $_RES " != 0 ] && FAILED=" $FAILED
133
+ P($RES ) ` pwd` $B ` echo ${_OUT} | tr ' \n' ' ' ` "
134
+ fi
135
+ echo " $_OUT "
136
+ done
137
+ fi
111
138
done
112
139
113
140
[ $RES = 0 ] && \
0 commit comments