Skip to content

Instantly share code, notes, and snippets.

@emacdona
Created August 20, 2020 18:41
Show Gist options
  • Save emacdona/5cabed252a0af733a4e06491136bec10 to your computer and use it in GitHub Desktop.
Save emacdona/5cabed252a0af733a4e06491136bec10 to your computer and use it in GitHub Desktop.
Ever get tired of having to type out branch names when you're trying to switch between local branches? This four line function will prompt you for a number instead (warning: uses zsh function and 'read' builtin syntax; you'll need to modify for bash).
# "checkout". Shows you local git branches and prompts you to select one by ordinal
co() {
echo "Which branch do you want to switch to?"
git branch | cat -n
read "NUM?> "
git checkout $(git branch | head -n $NUM | tail -n 1)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment