EvanLovely
6/6/2014 - 4:05 AM

git-checkout-helper.sh

# Git Checkout Helper
gitch() {
    git branch
    echo "Branch to checkout? (Fuzzy searching from left to right with space support)"
    read branch
    branches=$(git branch | egrep -i "${branch// /.*}" | tr -d ' ')
    count=$(echo "$branches" | egrep -c ".")
    if [ "$count" = "1" ]; then
        git checkout $(echo $branches | tr -d '\n' | tr -d '*')
    elif [[ "$count" = "0" ]]; then
        echo "No branches matched"
    else
        echo "Need to match a single branch. Found these:"
        echo "$branches"
    fi
}