-
Notifications
You must be signed in to change notification settings - Fork 0
/
git-cob
executable file
·51 lines (46 loc) · 838 Bytes
/
git-cob
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
#! /bin/bash
set -u
if [ $# -ne 1 ]; then
echo "Missing argument"
exit 1
fi
git fetch --all
inp=$1
br=$(git branch -l --format="%(refname:lstrip=2)" | grep -i "$inp")
if [ ${VERBOSE:-0} -ne 0 ]; then
echo $br
fi
cnt=$(echo $br | wc -w)
case $cnt in
0)
echo "No match found, searching on remote branches..."
br=$(git branch -r --format="%(refname:lstrip=3)" | grep -i "$inp")
cnt=$(echo $br | wc -w)
case $cnt in
0)
echo "No match found"
exit 1
;;
1)
git checkout $br -q
;;
*)
echo "Found $cnt remote matches"
for w in $br; do
echo $w
done
exit 2
;;
esac
;;
1)
git checkout $br -q
;;
*)
echo "Found $cnt matches"
for w in $br; do
echo $w
done
exit 2
;;
esac