-
Notifications
You must be signed in to change notification settings - Fork 0
/
gitDeleteBranchLocal
executable file
·62 lines (52 loc) · 1.83 KB
/
gitDeleteBranchLocal
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/bin/bash
######################################################
# Deletes a local branch. If we are on the local #
# branch will check no uncommitted changes, and #
# if not will checkout develop before deleting #
# local branch. Lastly runs a check to see if it #
# exists in remote and prints warning if it does #
######################################################
source ~/bash-helpers/_colours
source ~/bash-helpers/_functions
branchName=$1
if [[ -z "$branchName" ]]; then
echo "${RED}You must pass a branch name to check as the 1st arg"
exit 1
fi
if [[ -z $(gitBranchExistsInLocal $branchName) ]]; then
echo "${RED}Branch '${branchName}' does not exist locally, nothing to delete${RESTORE}"
gitBranchList -l
exit 1
fi
# Check if we are on the branch we want to delete
if [[ $(git branch | grep \* | cut -d ' ' -f2) == "$branchName" ]]; then
# Check if there are any uncommitted changes
if [[ $(git status --porcelain) ]]; then
while true; do
read -p -r "${RED}Warning: You have uncommitted changes which may relate '${branchName}'. Would you like to abort the delete so you can commit or stash them first?${RESTORE} (y/n) " yn
case $yn in
[Yy]*)
echo 'Exiting...'
exit 1
;;
[Nn])
echo 'Continuing...'
break
;;
*) echo "Please answer yes or no." ;;
esac
done
fi
# Checkout develop
echo "${BLUE}Checking out develop..${RESTORE}"
gitCheckoutPullDevelop
fi
# Delete the branch
git branch -d "$branchName"
echo "${GREEN}Branch '${branchName}' deleted locally!${RESTORE}"
# Pop a notice in the terminal if the branch exists on remote
if [[ $(gitBranchExistsInRemote "$branchName") ]]; then
echo ""
echo ""
echo "${PURPLE}Notice: Branch '${branchName}' exists on remote, if you need to delete that too...${RESTORE}"
fi