Created
April 16, 2014 19:23
-
-
Save EvanLovely/10923201 to your computer and use it in GitHub Desktop.
Git Checkout Helper
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment