The general scripting command for working with references is git for-each-ref
.
Branch references live in the refs/heads/
part of the name-space, so use git for-each-ref refs/heads
to obtain them all.
By default, git for-each-ref
prints three items: '%(objectname) %(objecttype) %(refname)'
, Use a different --format
to change this. In this case, you probably want:
git for-each-ref --format='%(refname:short)' refs/heads
but see the documentation for all the available formatting directives. (Note also that git for-each-ref
got a fair bit of attention in git 2.6 and 2.7: --contains
, --merged
, --no-merged
, and --points-at
are new. In older versions of git, the first three are only available via git branch
.)