Skip to content

Instantly share code, notes, and snippets.

@davidstosik
Forked from remino/git-deploy
Last active December 21, 2015 18:49
Show Gist options
  • Save davidstosik/6350184 to your computer and use it in GitHub Desktop.
Save davidstosik/6350184 to your computer and use it in GitHub Desktop.
#!/bin/sh
# git-deploy
#
# - Make sure your deployment environments on Heroku are set as Git remotes:
# git remote add production git@heroku.com:example-production.git
# git remote add staging git@heroku.com:example-staging.git
#
# - Have branch names matching those environments:
# git checkout -b production
# git push origin production
# git checkout -b staging
# git push origin staging
#
# - Call git deploy branch_name:
# It will call "git push branch_name branch_name:master" to deploy your app.
git_deploy() {
[ $# -lt 1 ] && git_deploy_usage && return 1
if [ -z "`git branch --list $1`" ]; then
git_deploy_error "Branch $1 does not exist."
fi
git remote show $1 > /dev/null 2>&1
if [ $? != 0 ]; then
git_deploy_error "Remote $1 does not exist."
fi
git push $1 $1:master
}
git_deploy_usage() {
echo "usage: git deploy [branch_name]"
echo
echo "The branch_name must match the Git remote name for Heroku."
}
git_deploy_error() {
echo $1 1>&2
exit 1
}
git_deploy $@
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment