EvanLovely
4/16/2014 - 7:23 PM

Git Checkout Helper

Git Checkout Helper

# Git Checkout Helper
gitco() {
    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
}