How to append branch name and commit to git archive output file?

git, git-archive

Solution

You can run this script:

#!/bin/sh
sha1=`git rev-parse --short --verify HEAD`
branch=`git symbolic-ref -q --short HEAD`

git archive -o latest_${branch}_${sha1}.zip HEAD

Call it `git-auto-archive`, for example, make it executable, put in your path, and run it with

git auto-archive

Problem

I'am using git archive to create a zip file with latest version/HEAD but would like to add the branch name and the commit to the zip filename. How can I achieve this?

Original source