Skip to content

Instantly share code, notes, and snippets.

@orottier
Last active November 12, 2015 18:07
Show Gist options
  • Save orottier/132f6c472dbc6aa9407f to your computer and use it in GitHub Desktop.
Save orottier/132f6c472dbc6aa9407f to your computer and use it in GitHub Desktop.
Pre Commit hook, proper stashing with unstash using bash traps (in case of errors halfway)
#!/bin/bash
#
# An example hook script to verify what is about to be committed.
# Called by "git commit" with no arguments. The hook should
# exit with non-zero status after issuing an appropriate message if
# it wants to stop the commit.
git stash -u --keep-index
trap "git stash pop --quiet --index; exit 1" SIGINT SIGTERM
# your checks, only working on staged changes
git stash pop --quiet
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment