forked from driesvints/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
git-clean.sh
executable file
·37 lines (31 loc) · 834 Bytes
/
git-clean.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
#! /bin/bash
# Check if main exists and use instead of master
function git_main_branch() {
command git rev-parse --git-dir &>/dev/null || return
local branch
for branch in main trunk; do
if command git show-ref -q --verify refs/heads/$branch; then
echo $branch
return
fi
done
echo master
}
RED='\033[0;31m'
NC='\033[0m'
branches=$(git branch --merged | grep -vE "^(\+|\*|\s*($(git_main_branch)|staging|development|develop|devel|dev)\s*$)" | awk '{ print $1; }')
if [ "$branches" = "" ]
then
echo "Already Clean 🚀"
exit
fi
echo "====!THESE BRANCHES WILL BE DELETED!===="
echo -e $RED"$branches"
read -p "$(echo -e "$NC""Are you sure? [yes/no] ")" confirm
if [ "$confirm" = "yes" ]
then
echo "$(git branch -d $branches)"
echo "Cleaned 🚀"
else
echo "Canceled 🙏"
fi