Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.