Skip to content

Automatically monitors and pushes changes across multiple Git repositories using inotifywait, ideal for continuous integration setups.

initialstacker/auto-git-push

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 

Repository files navigation

Auto Git Push

This Bash script continuously monitors multiple Git repositories listed in an external file for file changes, and automatically stages, commits, and pushes those changes.

Features

  • Watches multiple repositories simultaneously from a list in an external file (repositories.txt).
  • Recursively detects file modifications, creations, and deletions.
  • Excludes .git directories and temporary files (*.swp, backups).
  • Automatically commits changes with a timestamp and a random number in the commit message.
  • Pushes changes to the main branch on the origin remote.
  • Runs indefinitely until manually stopped.
  • Each repository is monitored in a separate background process for efficiency.

Requirements

  • Bash shell on Linux or Unix-like systems.
  • inotify-tools package installed (provides the inotifywait utility).
  • 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.

Usage

  1. List absolute paths to your Git repositories, one per line, in a file named repositories.txt.
  2. Run the script to monitor all listed repositories simultaneously.
  3. The script runs indefinitely, monitoring changes and auto-pushing commits.

Recommended Use with Supervisord

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.

Basic Supervisord Configuration Tips

  • Specify absolute paths for the script and commands inside.
  • Set autostart=true and autorestart=true for resilience.
  • Define the user that has appropriate permissions.
  • Set environment variables like PATH explicitly.
  • 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"

Notes

  • 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 push command 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.

License

This project is licensed under the MIT License.

About

Automatically monitors and pushes changes across multiple Git repositories using inotifywait, ideal for continuous integration setups.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages