I wanted to automate a build step that used the current git branch name. Here’s how to get it from within a Makefile:

BRANCH := $(shell git rev-parse --abbrev-ref HEAD)

BRANCH will then contain the branch name and can be used like a normal Makefile variable.