#!/bin/bash set -x # use a mandatory first arg of "run" when not running as GIT_SSH if [ "run" != "$1" ]; then # just exec ssh with some extra arguments exec ssh \ -i "$git_publish_keyfile" \ -o "StrictHostKeyChecking no" \ "$@" fi # running as git push script export GIT_SSH="$0" # set some defaults if not already set # git_tag="" # if set then pushing tag instead of branch git_force="" # parse commandline arguments # shift # drop the mandatory "run" argument while (( $# > 0 )) ; do case $1 in --local_branch) git_local_branch=$2 shift ;; --remote_branch) git_remote_branch=$2 shift ;; --remote_repo) git_remote_repo=$2 shift ;; --tag) git_tag=$2 shift ;; -f|--force) git_force="-f" ;; --keyfile) export git_publish_keyfile=$2 shift ;; esac shift done [ -n "$git_publish_keyfile" ] || { echo "--keyfile KEYFILENAME is required"; exit 1; } remote_name=remote_random_$RANDOM git remote add $remote_name $git_remote_branch if [ $git_tag ] then git push $git_force $git_remote_repo $git_tag else git push $git_force $git_remote_repo $git_local_branch:refs/heads/$git_remote_branch fi # cleanup git remote rm $remote_name exit 0