Add this snippet to your .*shrc
.
gx() {(
set -e
# If working tree dirty bar staged content...
if git status --porcelain | grep -v '^. ' >/dev/null; then
echo "⮑ Temporarily stashing unstaged and untracked content."
git stash push --keep-index --include-untracked
unstash() {
if [ -z "$unstashed" ]; then
echo "⮐ Restoring stashed content."
git restore . # in case the command made local changes
git stash pop --index
unstashed=1
fi
}
trap unstash EXIT SIGINT
fi
("$@") && echo 👍 || echo 💥
)}
Now you can run commands against a clean working tree.
gx make test