Skip to content

Instantly share code, notes, and snippets.

@tkirby
Created November 15, 2012 11:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tkirby/4078053 to your computer and use it in GitHub Desktop.
Save tkirby/4078053 to your computer and use it in GitHub Desktop.
Display menu of local git branches and allow to choose which to checkout by number.
#!/bin/bash
branches=()
eval "$(git for-each-ref --shell --format='branches+=(%(refname:short))' refs/heads/)"
# Set the prompt for the select command
PS3="Select a branch. 'q' to quit: "
select branch in "${branches[@]}"
do
if [ -n "$branch" ]; then
git checkout $branch
fi
break
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment