-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgit_d
executable file
·45 lines (40 loc) · 1.03 KB
/
git_d
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
#!/bin/sh
# GIT delete branch by full or partial name.
. $(dirname $0)/lib/GitLib.sh;
if [ -z "$1" ] || [ "$1" = "-p" ]
then
echo "Specify branch to delete.";
return 1; #exit function
fi
mainBranch=$(GitLib_GetMasterOrMain);
if [ $(GitLib_IsCurrentBranchMaster) = "0" ]
then
git checkout $mainBranch;
fi
if [ "$2" = "-b" ]
then
# Delete using a full branch name.
GitLib_DeleteLocalBranch $1;
else
response=$(GitLib_GetBranchNameFromPartial $1);
case $response in
'0')
echo -e "\nNo branch containing '$1' exists locally.\n";
;;
'2')
echo -e "\nBe more specific. The partial name '$1' exists in multiple local branches:";
git branch | grep $1 -i;
echo "";
;;
*)
read -p "Delete local branch '$response'? (y/n) " confirmResponse
if [ $confirmResponse = "y" ]
then
GitLib_DeleteLocalBranch $response;
echo 'Local branch deleted.';
else
echo "Delete aborted.";
fi
;;
esac
fi