Skip to content

Instantly share code, notes, and snippets.

@axel-angel
Created August 24, 2025 19:31
Show Gist options
  • Select an option

  • Save axel-angel/8ae20a902f7bb4557a714fd74096bc89 to your computer and use it in GitHub Desktop.

Select an option

Save axel-angel/8ae20a902f7bb4557a714fd74096bc89 to your computer and use it in GitHub Desktop.
Git auto commit script (shell)
#!/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