Create Release ZIP Files from Git Tags

GitHub provides a really nice way of creating release zip files for any of your GitHub projects. Here is a very simple shell script that can be used with any non-GitHub repository for creating release ZIP files out of Git tags:

#!/bin/sh

# Specify the project directory that contains .git
slug="project-dir"

# Specify release directory
dest="releases"

# Store releases in release directory
mkdir -p $dest

# Set the git working dir inside our project
export GIT_DIR=$slug/.git

# Get the latest tag
tag=$(git describe --tags --abbrev=0)

# Create a zip file out of the latest tag release
git archive $tag --prefix="$slug/" --format=zip --output="./$dest/$slug-$tag.zip"

echo "Created $dest/$slug-$tag.zip"

Where slug is the directory of your repository that contains .git, and dest is the directory for storing release ZIP files.

Place this script one level below your project directory, name it do-release and make sure it’s executable (chmod +x do-release).

Please leave a comment if you know how to achieve this using Git hooks.

Never lose a single business lead or enquiry again! Get my latest plugin Storage for Contact Form 7 now!

Buy now for only $19 →

Leave a Reply