For instance, this is my git dotfile doing that to display branches for a cherry-pick alias:
https://github.com/jakub-g/dotfiles/blob/master/git.profile#...
(_gitbranches() is defined at the beginning)