Last active
December 14, 2015 19:18
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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