-
Notifications
You must be signed in to change notification settings - Fork 0
/
gip-branch-delete
executable file
·54 lines (48 loc) · 1.21 KB
/
gip-branch-delete
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
function usage() {
echo ""
echo "Usage: gip-branch-delete [-r|--remote] [-f|--force] <branch> [--echo]"
echo " --remote: Attempt to delete from the server you push to. "
echo " --force: When git fights back, tell it to shut up and do it. "
echo " --echo: Echo-only; no changes made."
echo ""
}
theD="d"
while [[ $1 != "" ]]; do
if [[ $1 == -h* || $1 == --h* || $1 == "" ]]; then
usage
exit 1
elif [[ $1 == -f || $1 == "--force" ]]; then
theD="D"
shift
elif [[ $1 == -echo || $1 == "--echo" ]]; then
echo=1
shift
elif [[ $1 == -r* || $1 == --r* ]]; then
shift
remote=true
elif [[ $1 == -* || $branch ]]; then
echo "Don't know what to do with: $1"
exit 1
else
branch="$1"
shift
fi
done
if [[ ! $branch ]]; then
echo "No branch!"
exit 1
fi
if [[ $remote ]]; then
echo -e "\nRemote delete #1:\n git push origin --delete $branch:"
if [[ ! $echo ]]; then
git push origin --delete "$branch"
fi
echo -e "\nRemote delete #2:\n git branch -$theD -r $branch:"
if [[ ! $echo ]]; then
git branch -$theD -r origin/$branch
fi
fi
echo -e "\nDelete local: \n git branch -$theD $branch"
if [[ ! $echo ]]; then
git branch -$theD "$branch"
fi