Skip to content

Instantly share code, notes, and snippets.

@hiro08gh
Created February 4, 2020 00:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hiro08gh/6051719d3c0afea30d59b97a7994dc6f to your computer and use it in GitHub Desktop.
Save hiro08gh/6051719d3c0afea30d59b97a7994dc6f to your computer and use it in GitHub Desktop.
デプロイシェル
# $ chmode 755 deploy.sh
# $ ./deploy.sh
#!/bin/bash
set -e
CLONE_TO=/path/to/clone
REPO_URL=git@github.com:hiro08gh/repos.git
BRANCH=master
echo git clone
if [ -d "$CLONE_TO" ]; then
cd $CLONE_TO
git fetch -p
git checkout -q $BRANCH
latest_rev=$(git ls-remote origin HEAD | awk '{print $1}')
current_rev=$(git rev-parse HEAD)
if [ "$latest_rev" != "$current_rev" ]; then
git reset --hard $(git log --pretty=format:%H | tail -1)
git pull
fi
else
git clone $REPO_URL $CLONE_TO
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment