-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgit-killb
executable file
·43 lines (32 loc) · 1.2 KB
/
git-killb
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
#!/bin/bash
# Copyright (c) 2019-2020 Benjamin Holt -- MIT License
if [ "$1" == "-h" -o "$1" == "--help" ]; then
cat <<USAGE
usage: git killb [ALIAS] Deletes local branch ALIAS and its associated
tracking branch, ALIAS defaults to ALLGIT_BRANCH
git killb -h|--help Print this message and exit
USAGE
exit 0
fi
Bold=`tput bold`
Off=`tput sgr0`
Alias="${1:-$ALLGIT_BRANCH}" # Killb is too destructive to default to current branch
if [ -z "$Alias" ]; then
echo "Must specify a branch directly or with allgit" >&2
exit 1
fi
Branch=`git branch --list "$Alias"`
if [ -z "$Branch" ]; then
echo "$Alias: branch not found" >&2
exit 1
fi
ConfigRemote=`git config bettergit.defaultremote`
: ${DefaultRemote:=${ConfigRemote:-"origin"}}
Upstream=`git rev-parse --abbrev-ref "$Alias@{upstream}" 2> /dev/null | sed -e "s:$DefaultRemote/::"`
git-dropb "$Alias" || exit 1
if [ "$Upstream" ]; then
git push "$DefaultRemote" -d "$Upstream" && echo "${Bold}Deleted upstream $Upstream${Off}"
fi
# Extract branch-pair from git
# git branch -vv | sed -e 's/^[* ] \([^ ][^ ]*\) *[a-fA-F0-9][a-fA-F0-9]* *\(\[origin\/\([^] ][^] ]*\)\]\)*.*/\1 \3/' | cut -d ' ' -f 2
###