Skip to content

Instantly share code, notes, and snippets.

@jeenuv
Last active September 2, 2015 13:54
Show Gist options
  • Select an option

  • Save jeenuv/6eef5533e9317c0eda60 to your computer and use it in GitHub Desktop.

Select an option

Save jeenuv/6eef5533e9317c0eda60 to your computer and use it in GitHub Desktop.
Hands-free git show-branch
#!/bin/bash
#
# Script for hands-free use of 'git show-branch', with the option of specifying
# unwanted refs by prefixing with ^ at the command line (syntax elsewhere
# permitted). Refs to be ignored permanently can be added to $sed_script below
# Main upstream branch
upstream="${upstream:-origin/master}"
# Refs pattern to always ignore
sed_script='
/.stgit$/d
'
# Process args
for i; do
case "$i" in
^*)
# Remove all refs at the comand line prefixed with ^
sed_script="$sed_script;/$i/d"
shift
;;
esac
done
# Get short names of all head refs, sorted by committer date. Then filter
# through sed
refs="$(git for-each-ref --format='%(refname:short)' --sort='committerdate' refs/heads/\* | sed "$sed_script")"
set -x
git show-branch --sparse $upstream $refs $@
# vim: set tw=80:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment