Skip to content

Instantly share code, notes, and snippets.

@bierbaum
Created June 17, 2010 20:57
Show Gist options
  • Save bierbaum/442761 to your computer and use it in GitHub Desktop.
Save bierbaum/442761 to your computer and use it in GitHub Desktop.
#!/bin/bash
MAXBRANCHES=30
function __list {
git reflog | grep ': checkout:' | awk '{print $8}' | grep -v submit_branch | uniq | head -$MAXBRANCHES | sort | uniq -c | sort -nr | awk '{print $2}' | cat -n
}
git branch 2>&1 > /dev/null || exit 1
CUR_BRANCH=`git branch | egrep '^\* ' | cut -d' ' -f2`
if [ "$1" == "" ]; then
echo "On $CUR_BRANCH" 1>&2
echo "Popular recent branches:" 1>&2
__list
else
NEWBR=`__list | head -n $1 | tail -1 | awk '{print $2}'`
git checkout $NEWBR
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment