Skip to content

Instantly share code, notes, and snippets.

@mhagger
Created March 27, 2016 07:17
Show Gist options
  • Save mhagger/f452d88e8ab771597551 to your computer and use it in GitHub Desktop.
Save mhagger/f452d88e8ab771597551 to your computer and use it in GitHub Desktop.
#! /bin/sh
# Display remote branches whose tips were authored by you, in order
# from oldest to youngest. List branches in the specified remote, or
# the default remote if no argument is provided.
usage() {
echo "usage: $0 [--format=FORMAT] [REMOTE]"
}
tab=$(printf "\t")
# The format the user wants to see. Tabs will be treated as column separators:
format="%(authordate:relative)$tab%(refname:short)"
while test $# -gt 0
do
case "$1" in
--format=*)
format="${1#--format=}"
shift
;;
--format)
format="$2"
shift 2
;;
--help)
usage
exit 0
;;
-*)
usage
exit 1
;;
*)
break
;;
esac
done
case $# in
0)
if remote="$(git config remotes.default)"
then
prefix="refs/remotes/$remote"
else
prefix="refs/remotes"
fi
;;
1)
case "$1" in
refs/remotes/*)
prefix="$1"
;;
refs/remotes)
prefix="$1"
;;
*)
prefix="refs/remotes/$1"
;;
esac
;;
*)
usage 1>&2
exit 1
;;
esac
git for-each-ref --format="$format$tab%(authoremail)" --sort=authordate "$prefix" |
sed -ne "s/$tab<$(git config user.email)>\$//p" |
column -s "$tab" -t
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment