Skip to content

Instantly share code, notes, and snippets.

@gergelypolonkai
Last active August 29, 2015 14:04
Show Gist options
  • Save gergelypolonkai/8af6a3e86b57dd4c250e to your computer and use it in GitHub Desktop.
Save gergelypolonkai/8af6a3e86b57dd4c250e to your computer and use it in GitHub Desktop.
List git branches and their remote tracking branch, if any
#! /bin/sh
COLUMN=`which column 2> /dev/null`
if test -z $COLUMN
then
echo "\`column' is not found in PATH. Cannot continue."
exit 1
fi
current_branch=`git rev-parse --abbrev-ref HEAD`
for branch in $(git for-each-ref --shell --format='%(refname)' refs/heads | sed -e s/^\'refs\\/heads\\/// -e s/\'$//)
do
remote=`git config branch.$branch.remote`
merge=`git config branch.$branch.merge | sed -e 's/^refs\/heads\///'`
[ x"$current_branch" == x"$branch" ] && echo -n '*'
echo -n "$branch"
if ! test -z $merge
then
echo -en "\t"
echo -n $remote
echo -n /
echo -n $merge
fi
echo
done | $COLUMN -t
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment