This script automatically watches a directory for changes and commits them to git with descriptive commit messages.
- Git for Windows
- PowerShell 5.0+
- Windows Terminal (recommended)
- Save the script as
git-autocommit.ps1 - Make sure you're in a git repository
- Open PowerShell in your git repository
- Run the script with the directory you want to watch:
.\git-autocommit.ps1 -WatchDir "C:\path\to\your\project"- The script will watch for file changes and automatically commit them with descriptive messages + Your reason which will be prompted from you!
- Press Ctrl+C to stop watching
- Automatically commits file changes as they happen
- Creates descriptive commit messages that include:
- Line numbers of changes
- Sample of inserted content
- Sample of removed content
- Type of change (Insertion, Deletion, Replacement)
- Handles new files and deleted files
- Skips hidden files and directories
The script uses PowerShell's FileSystemWatcher class to monitor file system events in real-time. When a file change is detected:
- The script extracts the line numbers and content that changed using
git diff - It creates a descriptive commit message with details about the changes
- The changed file is added to git staging
- The changes are committed with the generated message
- Make sure you're running the script from within a git repository
- If files aren't being detected, check that they're not in your
.gitignore - If you get permission errors, try running PowerShell as administrator
This script automatically watches a directory for changes and commits them to Git with descriptive commit messages.
- Git
- fswatch (
brew install fswatch) - Bash or Zsh shell
- Save the script as
git-autocommit.sh - Make the script executable:
chmod +x git-autocommit.sh- Open Terminal in your git repository
- Run the script with the directory you want to watch:
./git-autocommit.sh /path/to/your/project- The script will watch for file changes and automatically commit them with descriptive messages + Your reason which will be prompted from you!
- Press Ctrl+C to stop watching
- Automatically commits file changes as they happen
- Creates descriptive commit messages that include:
- Line numbers of changes
- Sample of inserted content
- Sample of removed content
- Type of change (Insertion, Deletion, Replacement)
- Skips hidden files and directories
- Compatible with macOS file system events
The script uses fswatch to monitor file system events in real-time. When a file change is detected:
- The script extracts the line numbers and content that changed using
git diff - It creates a descriptive commit message with details about the changes
- The changed file is added to git staging
- The changes are committed with the generated message
- If you see
fswatch not found, install it with Homebrew:brew install fswatch - Make sure you're running the script from within a git repository
- If files aren't being detected, check that they're not in your
.gitignore