Forked from mislav/git-recently-checkout-branches.sh
Created
November 14, 2018 10:24
-
-
Save roland-ewald/f7fd3ad0cf173c29f535040e275cf029 to your computer and use it in GitHub Desktop.
Show list of recently checked-out branches in reverse-chronological order
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 | |
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