Make this file executable and add it to your path
grco [some-text]
#!/bin/bash | |
BRANCHES=$(git branch -ra | grep $1) | |
NUM=$(echo "$BRANCHES" | wc -l) | |
# check for empty | |
if [ "X$BRANCHES" = "X" ] | |
then | |
echo "No branch matches $1" | |
fi | |
if [ $NUM -eq 1 ] | |
then | |
remote="remotes/origin/" | |
branch=$(echo $BRANCHES | awk '{ gsub(/remotes\/origin\//,""); print}') | |
git checkout $branch | |
fi | |
list=() | |
i=0 | |
if [ $NUM -gt 1 ] | |
then | |
while read -r line; do | |
(( i++ )) | |
branch=$(echo $line | awk '{ gsub(/remotes\/origin\//,""); print}') | |
echo "$i: $branch" | |
list+=("$branch") | |
done <<< "$BRANCHES" | |
echo -n "Please choose one of the branches: " | |
read index | |
git checkout ${list[index-1]} | |
fi |