Skip to content

Instantly share code, notes, and snippets.

@itavero
Last active December 14, 2015 19:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save itavero/5135239 to your computer and use it in GitHub Desktop.
Save itavero/5135239 to your computer and use it in GitHub Desktop.
Bash script to export the current branch/rev of a Git repository as a ZIP archive.
#!/bin/bash
# Easy Git Export Command
# Copyright (C) 2013, Arno Moonen <info@arnom.nl>
#
# Example usage (from within a Git repository, when using the alias):
# git-export ~/Desktop
# -> Creates the exported archive on your desktop.
# git-export
# -> Creates the exported archive one level up in your path.
#
# # # # # # # # # # # # # # # # # # # # # #
# Get path (first argument)
if [ -n "$1" ]; then
rpath=$1
else
rpath=`pwd`
rpath="${rpath}/.."
fi
# Get information about current repo
rdir=${PWD##*/}
rbranch=`git rev-parse --abbrev-ref HEAD`
rrev=`git rev-parse --short HEAD`
rfilename="${rdir}_${rbranch}_${rrev}.zip"
# Create archive
echo "Export ${rdir} (${rbranch}) to ${rfilename} ..."
echo "---"
echo "Adding files:"
git archive ${rbranch} --format zip -9 -v -o "${rpath}/${rfilename}"
echo "---"
echo "Done."
# Open target directory
open ${rpath}
# Comment the line above, if you do not wish to open
# the target directory when the export is finished.
# Add this to your ~/.bash_profile (Mac) to create an alias
# ----------------------------------------------------------------------
# Alias for git-export
alias git-export='/path/to/git_export.sh'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment