Skip to content

Instantly share code, notes, and snippets.

@EvanLovely
Created April 16, 2014 19:23
Show Gist options
  • Save EvanLovely/10923201 to your computer and use it in GitHub Desktop.
Save EvanLovely/10923201 to your computer and use it in GitHub Desktop.
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
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment