Skip to content

Instantly share code, notes, and snippets.

@carlosayam
Last active January 4, 2022 03:30
Show Gist options
  • Save carlosayam/5316969 to your computer and use it in GitHub Desktop.
Save carlosayam/5316969 to your computer and use it in GitHub Desktop.
Output branches description in Git (bash version)
#!/bin/bash
set -f
git branch | while read line; do
current=' '
name=${line##\* } ## removes leading * for current
if [ ! "$name" = "$line" ]; then current='* '; fi
description=`git config branch.$name.description`
echo "$current" $name : $description
done
@carlosayam
Copy link
Author

Credit: An alternative to gist

@alexgorbatchev
Copy link

awesome, thanks! here's a upgrade

green=`tput setaf 2`
reset=`tput sgr0`

git-branch-list() {
  set -f
  git branch | while read line; do
    current="  "
    name=${line##\* }   ## removes leading * for current

    if [ ! "$name" = "$line" ]; then
      current="${green}* "
    fi

    description=`git config branch.$name.description`

    if [ "$description" != "" ]; then
      description=" : $description"
    fi

    echo "${reset}${current}${name}${description}"
  done
}

@SaganRitual
Copy link

SaganRitual commented Oct 13, 2016

@alexgorbatchev Thank you! I am astonished that git doesn't do this automatically. Thank you so much.

P.S. It disabled globbing on my system. Here's an update.

green=`tput setaf 2`
reset=`tput sgr0`

git-branch-list() {
  set -f
  git branch | while read line; do
    current="  "
    name=${line##\* }   ## removes leading * for current

    if [ ! "$name" = "$line" ]; then
      current="${green}* "
    fi

    description=`git config "branch.$name.description"`

    if [ "$description" != "" ]; then
      description=" : $description"
    fi

    echo "${reset}${current}${name}${description}${reset}"
  done
  set +f
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment