Additional Git safety hooks.
shell-guard is a lightweight bash utility designed to protect your repository from accidental commits during "dirty" states. It ensures that critical operations—like releases or merges—only proceed when your working directory is clean, or after a safety snapshot has been taken.
- Deterministic: Validates your git state before you execute irreversible commands.
- Safety Snapshots: Automatically archives diffs and untracked files into
.guardian/snapshots/if you're working in a dirty repo. - CI-Ready: Returns standard exit codes for easy integration into build pipelines.
- Drop
shell-guard.shinto your project'sbin/orscripts/folder. - Grant execution permissions:
chmod +x shell-guard.sh.
Halt if repo is dirty:
./shell-guard.sh --check || exit 1Force a state snapshot:
./shell-guard.sh --snapshot- Fail-Fast: Catch configuration and state drift before it enters your history.
- Risk-Averse: Designed to prioritize data safety by observing and archiving state rather than modifying it.
- Zero Dependencies: Pure bash. Works everywhere git does.
This is a small tool I built for my own workflow and I’m sharing it in case it helps others.
- Tested on: Linux (TUXEDO OS)
- Other platforms: may work, but not regularly tested
- Transparency: Source code is heavily commented to explain logic and known limitations.
Please review scripts before running, and try them on non-critical data first.
MIT