Skip to content

Instantly share code, notes, and snippets.

@jamesnvc
Created January 27, 2017 17:14
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jamesnvc/5c4f2970df330252d29f95ce9cd26623 to your computer and use it in GitHub Desktop.
Save jamesnvc/5c4f2970df330252d29f95ce9cd26623 to your computer and use it in GitHub Desktop.
Shell script template to only act on "clean" git repos
#!/bin/bash
set -euo pipefail
set +e
if ! git diff-files --quiet --ignore-submodules ; then
echo "Uncommited changes; stash or commit before deploying"
exit 1
fi
if ! git diff-index --cached --quiet HEAD --ignore-submodules ; then
echo "Staged but uncommited changes; commit before deploying"
exit 2
fi
set -e
# do stuff
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment