A Python script that generates customized bash scripts for automated git commits with various configuration options.
Note: This script is designed for UNIX (Linux, macOS, BSD, etc.) systems. It may not work as expected (if at all) on Windows.
- Flexible change tracking: Track all changes, staged changes only, or custom files/patterns
- Commit message customization: Add prefixes and suffixes to commit messages
- Multiple repository support: Push to one or more repositories
- Pre/post command execution: Run custom commands before and after git operations
- Branch management: Optionally switch to specific branches before pushing
- Error handling: Robust error checking and colored output
- Backup creation: Automatically backs up existing scripts
Run the generator and follow the interactive prompts:
python generate_commit_script.pyThe generator will ask for:
- Script name: Name of the generated bash script (default:
auto_commit.sh) - Change tracking: What changes to track
- All changes (
git add .) - Staged changes only
- Custom files/patterns
- All changes (
- Commit message formatting: Optional prefix and suffix
- Target branch: Branch to push to (optional)
- Push repositories: List of repositories to push to
- Pre-commands: Commands to run before committing
- Post-commands: Commands to run after pushing
Once generated, use your script like this:
./auto_commit.sh "Your commit message here"Generate a simple script that commits all changes and pushes to origin:
# Generator inputs:
# Script name: auto_commit.sh
# Track changes: All changes
# Commit prefix: [feat]
# Push repositories: origin
# Usage:
./auto_commit.sh "Add new feature"
# Results in commit message: [feat] Add new feature# Generator inputs:
# Script name: deploy.sh
# Track changes: Custom files (*.py, *.js)
# Commit prefix: [deploy]
# Commit suffix: - automated
# Target branch: main
# Push repositories: origin, backup
# Pre-commands: npm test, python -m pytest
# Post-commands: npm run build, docker-compose up -d
# Usage:
./deploy.sh "Update application"
# Results in commit message: [deploy] Update application - automated# Generator inputs:
# Track changes: Custom files
# Files to track:
# src/*.py
# docs/*.md
# requirements.txt
# Generated script will only commit these specific filesThe generated bash scripts include:
- Error handling: Exit on any error with descriptive messages
- Colored output: Info, success, and error messages with colors
- Git repository validation: Check if running in a git repository
- Change detection: Skip commit if no changes exist
- Parameter validation: Require commit message as parameter
- Executable permissions: Automatically made executable
Commit Script Generator/
├── generate_commit_script.py # Main generator script
├── README.md # This documentation
└── auto_commit.sh # Generated script (example)
- Python 3.6+
- Git
- Bash shell
- All changes:
git add .- Tracks all modified and new files - Staged only: Uses already staged files, no
git addcommands - Custom: Specific files/patterns you define
- Prefix: Text added before the commit message
- Suffix: Text added after the commit message
- Example: With prefix
[feat]and suffix- automated, message "Fix bug" becomes[feat] Fix bug - automated
- Single or multiple repositories
- Branch-specific pushing
- Current branch or specified branch
- Pre-commands: Run before git operations (e.g., tests, linting)
- Post-commands: Run after successful push (e.g., deployment, notifications)
- Commands are executed with error checking
chmod +x your_script_name.shEnsure you're running the script in a directory with a .git folder.
Commands are executed with set -e, so any failing command will stop the script. Make sure your commands are properly formatted and accessible.
# Generator configuration for development:
# - Track: All changes
# - Prefix: [dev]
# - Pre-commands: npm run lint, npm test
# - Post-commands: npm run dev
./dev_commit.sh "Implement user authentication"# Generator configuration for deployment:
# - Track: Custom files (dist/, package.json)
# - Prefix: [deploy]
# - Branch: production
# - Pre-commands: npm run build
# - Post-commands: pm2 reload all
./deploy.sh "Version 1.2.0"# Generator configuration for docs:
# - Track: Custom files (*.md, docs/**)
# - Prefix: [docs]
# - Push repositories: origin, docs-fork
./docs_commit.sh "Update API documentation"