Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save nilbus/bd1cbefdaf09fbd78a0d to your computer and use it in GitHub Desktop.
Save nilbus/bd1cbefdaf09fbd78a0d to your computer and use it in GitHub Desktop.
Show list of recently checked-out branches in reverse-chronological order
#!/bin/bash
set -e
git reflog -n100 --pretty='%cr|%gs' --grep-reflog='checkout: moving' HEAD | {
seen=":"
git_dir="$(git rev-parse --git-dir)"
while read line; do
date="${line%%|*}"
branch="${line##* }"
if ! [[ $seen == *:"${branch}":* ]]; then
seen="${seen}${branch}:"
if [ -f "${git_dir}/refs/heads/${branch}" ]; then
printf "%s\t%s\n" "$date" "$branch"
fi
fi
done
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment