Skip to content

Commit 66976d3

Browse files
committed
git-branchkill : add a way to push branch deletion to remote repos (all known)
1 parent aa4ca12 commit 66976d3

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

git-branchkill

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
git_branch_kill() {
88
EXEC=""
99
LOCALKILL=-d
10+
REMOTEKILL=no
1011
REPODIRS=""
1112

1213
# We do parse some outputs, so keep it single-language
@@ -22,6 +23,7 @@ while [ $# -gt 0 ]; do
2223
echo "help clean up after a branch has been merged and is no longer used"
2324
echo " -n Read-only mode to see what might be done"
2425
echo " -D Allow destruction of un-merged local branches"
26+
echo " -DD Cause the remote repo(s) to forget named branch(es)"
2527
echo " -R 'dirs...' List one or more local repositories (directories)"
2628
echo " to act upon; the parameter may be specified more than once,"
2729
echo " and its argument may be a space-separated list of directories"
@@ -38,6 +40,10 @@ while [ $# -gt 0 ]; do
3840
echo "Info: Allowing destruction of un-merged local branches!" >&2
3941
shift 1
4042
;;
43+
-DD) REMOTEKILL=yes
44+
echo "Info: Pushing destruction of named branches to remotes!" >&2
45+
shift 1
46+
;;
4147
-R) if [ -n "$2" ] ; then
4248
for D in $2 ; do
4349
if [ -d "$D" ]; then
@@ -108,6 +114,27 @@ L($RES) `pwd` $B `echo ${_OUT} | tr '\n' ' '`"
108114
fi
109115
echo "$_OUT"
110116
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
111138
done
112139

113140
[ $RES = 0 ] && \

0 commit comments

Comments
 (0)