Skip to content

Instantly share code, notes, and snippets.

@anthonybishopric
Created May 29, 2013 23:02
Show Gist options
  • Save anthonybishopric/5674518 to your computer and use it in GitHub Desktop.
Save anthonybishopric/5674518 to your computer and use it in GitHub Desktop.
Steven Cipolla's branch switching script
#!/bin/bash
OIFS=$IFS
IFS=$'\n'
count=10
if [ -n "$1" ]; then
count=$1
fi
branches=( $(git for-each-ref --sort='-committerdate' --count=$((count+3)) --format='(%(refname:short)) %(subject), %(committerdate:relative)' refs/heads | grep -v 'v5') )
for i in ${!branches[@]}; do
let idx=i+1
echo -e "[$idx]\t${branches[$i]})"
done
echo 'Enter branch number, nothing to exit:'
read b
if [[ "$b" -gt "0" ]] && [[ "$b" -le "$count" ]]; then
let idx=b-1
git checkout $(echo "${branches[$idx]})" | sed 's/(\(\S*\)).*/\1/')
fi
IFS=$OIFS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment