Forked from mislav/git-recently-checkout-branches.sh
Created
November 23, 2015 16:48
-
-
Save nilbus/bd1cbefdaf09fbd78a0d to your computer and use it in GitHub Desktop.
Show list of recently checked-out branches in reverse-chronological order
This file contains hidden or 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 | |
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