Skip to content

Instantly share code, notes, and snippets.

@sumeet
Forked from jordan-brough/git-recent
Created September 6, 2016 20:57
Show Gist options
  • Save sumeet/2df51fa10b7345c0ff9db43cc1cca403 to your computer and use it in GitHub Desktop.
Save sumeet/2df51fa10b7345c0ff9db43cc1cca403 to your computer and use it in GitHub Desktop.
Git: Display a list of recently checked out branches/tags/commits
#!/usr/bin/env bash
# Source: https://gist.github.com/jordan-brough/48e2803c0ffa6dc2e0bd
# Download this script as "git-recent" (no extension), chmod it to be executable and put it in your
# path somewhere (e.g. /usr/bin). You can then use it via `git recent` from inside any git repo.
# Example:
#
# $ git recent -n 5
# master
# stable
# master
# some-cool-feature
# feature/improve-everything
usage()
{
echo "usage: git recent [-n lines]"
}
while getopts "hn:" opt; do
case $opt in
h)
usage
exit 1
;;
n)
NUM=$OPTARG
;;
\?)
usage
exit 1
;;
esac
done
NUM=${NUM-10} # default to 10 lines
# This: `awk ' !x[$0]++'` removes duplicates. See http://stackoverflow.com/questions/11532157
git reflog | egrep -io "moving from ([^[:space:]]+)" | awk '{ print $3 }' | awk ' !x[$0]++' |
# remove detached heads
egrep -v '[a-f0-9]{40}' |
head -n $NUM
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment