public
Created

Display menu of local git branches and allow to choose which to checkout by number.

  • Download Gist
gco.sh
Shell
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
#!/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

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.