Created
May 29, 2013 23:02
-
-
Save anthonybishopric/5674518 to your computer and use it in GitHub Desktop.
Steven Cipolla's branch switching script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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