-
-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy path.cleanup-branches.sh
executable file
·47 lines (40 loc) · 1.18 KB
/
.cleanup-branches.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/bin/bash
#
# Srcipt to clean up branches that are no longer in use.
#
# Due to gitlab mirroring back and forth, the branches are not
# being deleted but put back in place again.
#
set -e
cd "`dirname \"$0\"`"
remotes=""
branches=""
for remote in `git remote`; do
echo -n "Choose branches from remote $remote? (Y/n) "
read
if [ -z "$REPLY" ] || [ "$REPLY" == "y" ] || [ "$REPLY" == "Y" ]; then
echo "Using remote $remote."
remotes="$remotes $remote"
fi
done
for branch in `git branch -r | grep -oE '[^/]+$' | sort | uniq | grep -vE 'master'`; do
echo -n "Delete branch $branch? (y/N) "
read
if [ "$REPLY" == "y" ] || [ "$REPLY" == "Y" ]; then
echo "Remembering $branch for deletion."
branches="$branches $branch"
else
echo "Keeping $branch."
fi
done
echo "Selected remotes to delete branches from: $remotes."
echo "Selected branches to delete: $branches"
echo -n "Start deleting? (Control+C to stop) "
read
for branch in $branches; do
echo " ---------- deleting $branch ---------- "
git branch -d "$branch" || true
for remote in $remotes; do
git push --delete "$remote" "$branch" || true
done
done