Git export from BitBucket
One of the consequences of moving to git is that I needed to get our deployment scripts working with it. The first requirement was an equivalent to svn export. This is simple enough, but, as usual, I wanted to save myself some effort and created a script that wrapped it up for me.
git-export.sh:
#!/bin/sh
#
# USAGE: export.sh REPO_NAME BRANCH_NAME [DIRECTORY_NAME] [BITBUCKET_ACCOUNT_NAME]
#
#
BITBUCKET_ACCOUNT_NAME=akrabat
GITROOT=git@bitbucket.org:${BITBUCKET_ACCOUNT_NAME}
if [ -z "$1" ]; then
echo "Usage is git-export.sh {repo_name} [{branch_name = master}] [{dir_name = repo_name}]"
exit 1
fi
REPO_NAME=$1
BRANCH_NAME=$2
THIS_DIR=$3
if [ -z "$BRANCH_NAME" ]; then
BRANCH_NAME=master
fi
if [ -z "$THIS_DIR" ]; then
THIS_DIR=$REPO_NAME
fi
if [ -d "$THIS_DIR" ]; then
echo "Error: directory '$THIS_DIR' already exists."
exit 1
fi
echo "Exporting $BRANCH_NAME branch of $REPO_NAME into ./$THIS_DIR..."
mkdir $THIS_DIR
git archive --format=tar --remote=$GITROOT/$REPO_NAME $BRANCH_NAME | tar -xf - -C $THIS_DIR
echo "Done"
echo ""
Not the most complicated script in the world, but I never need to think about it again and it’s easy to call from Phing and other deployment scripts and doesn’t require a local clone to exist.