Git: create archive

Git

As you may know Git has wonderful feature create archive of files in repository.

For example, you can create Bash script to automate making of Git archives:

#!/bin/bash

GIT_DIR="/home/taras/git_working_copy_dir/"
ZIP_NAME="_git_archives/taras-`date +'%Y%m%d%H%M'`.zip"

cd ${GIT_DIR}
pwd
# make zip archive from current git HEAD branch
git archive HEAD --format=zip -o ${ZIP_NAME}
# delete some files from zip archive
zip -d ${ZIP_NAME} ./.gitignore
#
echo "Archive file ${ZIP_NAME} is:"
ls -alh ${ZIP_NAME}
#
echo "Archive content:"
unzip -l ${ZIP_NAME} |more

Also, you can use tar format instead of zip and then to gzip it.

# git archive --format=tar --prefix=git-1.0/ v1.0 | gzip >git-1.0.tar.gz

v1.0 – is tag name of release to archive
–prefix=git-1.0/ – adds folder git-1.0/ inside archive
–format=tar – use tar format