Skip to content

Instantly share code, notes, and snippets.

@lmarlow
Created November 6, 2013 20:30
Show Gist options
  • Save lmarlow/7343546 to your computer and use it in GitHub Desktop.
Save lmarlow/7343546 to your computer and use it in GitHub Desktop.
Prints the branches with the most recent commits
#!/bin/bash
#############################################################################
usage () {
printf "%s" "\
usage: git recent [-r remote] [count]
Prints the branches with the most recent commits.
options:
-r remote name
-h prints help
"
}
args=""
while [ $OPTIND -le $# ]
do
if getopts "r:h" option
then
case $option in
(r) remote=$OPTARG ;;
(h) usage
exit 0 ;;
(*) usage | head -n 1
exit 2 ;;
esac
else
args="$args \"\${$OPTIND}\""
OPTIND=$(($OPTIND + 1))
fi
done
eval set -- "$args"
#############################################################################
count=${1:-10}
pattern=${remote:+refs/remotes/}${remote}
pattern=${pattern:-refs/heads/}
git for-each-ref --count=${count} --sort='-committerdate:iso8601' \
--format="%(committerdate:iso8601) %(refname:short)" ${pattern}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment