Skip to content

Instantly share code, notes, and snippets.

@msadouni
Created March 9, 2012 15:05
Show Gist options
  • Save msadouni/2006889 to your computer and use it in GitHub Desktop.
Save msadouni/2006889 to your computer and use it in GitHub Desktop.
Export a git repository content in a directory
#!/bin/bash
if [ -z "$1" ]
then
echo "usage: git-export <project-name> <branch-name|master>"
exit
fi
site_name=$1
if [ -z "$2" ]
then
branch='master'
else
branch=$2
fi
export_dir="${HOME}/tmp/exports"
site_dir="${HOME}/Sites"
revision=$(git --git-dir=$site_dir/$site_name/.git rev-parse $branch)
rm -rf $export_dir/$site_name/
rm "$export_dir/$site_name"*.tgz
mkdir -p $export_dir/$site_name
git archive $revision | tar -x -C $export_dir/$site_name/
echo $revision > $export_dir/$site_name/VERSION.txt
cd $export_dir/$site_name
tar -czf $export_dir/$site_name-$revision.tgz ./*
exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment