A Python script that automatically commits and pushes changes to Git repositories at scheduled intervals.
- Automatic git commit and push functionality
- Configurable scheduling via Windows Task Scheduler
- Repository URL memory (asks once, remembers forever)
- Detailed logging of all operations
- Support for custom branch names
- File change tracking and statistics
- Python 3.6 or higher
- Git installed and configured
- GitHub account with personal access token
- Clone or download this repository to your local machine
- Ensure Python is installed (
python --versionto check) - Install Git if not already installed
-
Edit
autopush.pyand update the following variables:USERNAME: Your GitHub usernameTOKEN: Your GitHub personal access tokenLOG_DIR: Directory for log files (default:C:\GitAutoPush)
-
Generate a GitHub personal access token:
- Go to GitHub Settings > Developer settings > Personal access tokens
- Generate new token with
repopermissions - Copy the token and paste it in the script
Navigate to your repository directory and run:
python C:\GitAutoPush\autopush.pyOn first run, the script will prompt for your GitHub repository URL. It will remember this URL for future runs.
Set up Windows Task Scheduler to run the script every 30 minutes:
- Press
Win + R, typetaskschd.msc, press Enter - Click "Create Task" (not "Basic Task")
- Name:
Git AutoPush - Triggers tab: New trigger, Daily, Repeat every 30 minutes, Duration: Indefinitely
- Actions tab: New action, Start a program
- Program: Path to Python executable
- Arguments: Full path to autopush.py
- Start in: Your repository directory
- The script checks if the current directory is a Git repository
- If no remote origin is configured, it prompts for the GitHub URL
- Creates or switches to an
auto-commitbranch - Checks for uncommitted changes
- If changes exist, commits them with timestamp and pushes to GitHub
- Logs all operations to the specified log directory
All operations are logged to:
- Console output for immediate feedback
- Log file:
C:\GitAutoPush\autopush.log
Logs include:
- Repository information
- Commit details
- Changed files and line statistics
- Push results
AutoPush/
├── autopush.py # Main script
├── README.md # This file
└── logs/ # Log files (created automatically)
- Ensure Git is properly configured with your credentials
- Verify your GitHub token has the correct permissions
- Check that the repository directory contains a
.gitfolder - Review log files for detailed error information