Skip to content

Instantly share code, notes, and snippets.

@rufhausen
Last active December 14, 2015 16:19
Show Gist options
  • Save rufhausen/5114025 to your computer and use it in GitHub Desktop.
Save rufhausen/5114025 to your computer and use it in GitHub Desktop.
This is my attempt to use Git to push to a remote server AND update a version.txt file that is then included and displayed in a web app with the most recent repository tag (1.0, etc.) and the abbreviated commit hash (i.e., the output of "git describe". Naming this file "push", you execute it while passing in the name of the git remote ("./push t…
#!/bin/bash
VERSION_FILE=version.txt
GIT_PATH=/usr/local/git/bin/git
REMOTE_PATH=[full remote path to application root]/$VERSION_FILE
LOCAL_PATH=[full local path to application root]/$VERSION_FILE
TEST_SERVER=[test ip/domain]
PROD_SERVER=[prod ip/domain]
if [ -z "$1" ]; then
echo 'no server parameter given'
exit
else
if [ $1 == "test" ]; then
SERVER=$TEST_SERVER
elif [ $1 == "prod" ]; then
SERVER=$PROD_SERVER
else
echo 'invalid server parameter'
exit
fi
$GIT_PATH push $1
echo "pushed to $1"
$GIT_PATH describe > $LOCAL_PATH
echo "updated version.txt"
scp $LOCAL_PATH $SERVER:$REMOTE_PATH
echo "copied version.txt to $1"
exit
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment