This Bash script continuously monitors multiple Git repositories listed in an external file for file changes, and automatically stages, commits, and pushes those changes.
- Watches multiple repositories simultaneously from a list in an external file (
repositories.txt). - Recursively detects file modifications, creations, and deletions.
- Excludes
.gitdirectories and temporary files (*.swp, backups). - Automatically commits changes with a timestamp and a random number in the commit message.
- Pushes changes to the
mainbranch on theoriginremote. - Runs indefinitely until manually stopped.
- Each repository is monitored in a separate background process for efficiency.
- Bash shell on Linux or Unix-like systems.
inotify-toolspackage installed (provides theinotifywaitutility).- Correct Git user configuration and authentication (SSH keys or HTTPS credentials) for each repository.
- Proper permissions for the user running the script on all repositories.
- List absolute paths to your Git repositories, one per line, in a file named
repositories.txt. - Run the script to monitor all listed repositories simultaneously.
- The script runs indefinitely, monitoring changes and auto-pushing commits.
It is strongly recommended to run this script under supervisord to ensure:
- The script is restarted automatically if it crashes.
- Easy management of the script as a persistent background service.
- Proper environment variables and user permissions can be configured.
- Logs can be collected and monitored systematically.
- Specify absolute paths for the script and commands inside.
- Set
autostart=trueandautorestart=truefor resilience. - Define the user that has appropriate permissions.
- Set environment variables like
PATHexplicitly. - Configure log files or disable logging if desired.
Example supervisord program snippet (replace paths and user accordingly):
[program:git_auto_push]
command=/bin/bash /path/to/auto_git_push.sh
user=your_username
autostart=true
autorestart=true
stdout_logfile=/var/log/git_auto_push.out.log
stderr_logfile=/var/log/git_auto_push.err.log
environment=PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
- Make sure Git credentials and SSH keys or HTTPS tokens are correctly set up for the user running the script.
- Adjust the branch name in the
git pushcommand if needed. - Monitor resource usage when watching many repositories in parallel.
This script combined with supervisord provides a reliable and automated way to keep multiple Git repositories updated continuously.
This project is licensed under the MIT License.