Skip to content

Instantly share code, notes, and snippets.

@doctorallen
Last active January 12, 2016 15:27
Show Gist options
  • Save doctorallen/cce850b920e9bd658597 to your computer and use it in GitHub Desktop.
Save doctorallen/cce850b920e9bd658597 to your computer and use it in GitHub Desktop.
Simple git deployment helper script
#!/usr/bin/env bash
if [ -r ./.deploy ]; then
echo "Reading config" >&2
. ./.deploy
fi
production=false
while getopts h:b:d:p opt; do
case $opt in
h) host=$OPTARG;;
b) branch=$OPTARG;;
d) dir=$OPTARG;;
p) production=true;;
\?) echo "Invalid option: -$OPTARG"; exit 1;;
esac
done
if [ "$production" = true ] ; then
if [ -z "$productionhost" ] ; then
echo "You have requested to deploy to production, but haven't specified a productionhost"
exit
fi
host=$productionhost
fi
if [ -z "$host" ] ; then
echo "Error: please define a host to deploy to."
read host
fi
if [ -z "$dir" ] ; then
echo "Error: please define a directory to deploy to."
read dir
fi
if [ -z "$branch" ] ; then
echo "Error: please define a branch to deploy to."
read branch
fi
ssh $host "cd $dir && git pull origin $branch"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment