Created
August 24, 2025 19:31
-
-
Save axel-angel/8ae20a902f7bb4557a714fd74096bc89 to your computer and use it in GitHub Desktop.
Git auto commit script (shell)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/sh | |
| # Auto-commit script with safety checks | |
| set -e | |
| if [ -z "$1" ]; then | |
| echo "Missing directory argument"; | |
| exit 1; | |
| else | |
| cd "$1"; shift; | |
| fi; | |
| if [ -z "$1" ]; then | |
| echo "Missing branch argument"; | |
| exit 1; | |
| else | |
| targetbranch="$1"; shift; | |
| fi; | |
| # Check if we're in a git repo and no operations in progress | |
| if ! git rev-parse --git-dir >/dev/null 2>&1; then | |
| echo "Not in a git repository"; | |
| exit 1; | |
| fi | |
| mybranch="$(git rev-parse --abbrev-ref HEAD)"; | |
| if [ "$mybranch" != "$targetbranch" ]; then | |
| echo "Git in different branch: $mybranch"; | |
| exit 1; | |
| fi | |
| if [ -f .git/MERGE_HEAD ] || [ -f .git/REBASE_HEAD ] || [ -f .git/CHERRY_PICK_HEAD ]; then | |
| echo "Git operation in progress, aborting"; | |
| exit 1; | |
| fi | |
| git add -A; | |
| git commit --quiet --no-status -m "auto commit" >/dev/null; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment