sync-it-all
is a script for synchronizing all Git repositories in a specified directory. The script ensures all repositories are up-to-date with their remote counterparts by pulling the latest changes. It handles uncommitted changes automatically by stashing them before switching branches.
- Synchronize all Git repositories in a directory with their remote.
- Automatically stashes uncommitted changes to ensure clean branch checkouts.
- Generates optional log files for detailed sync operations.
Important
This script requires Git to be installed and available in your system's PATH.
-
Download and Give Execute Permissions:
You can download the script directly or use
curl
:sudo curl -L -o /usr/local/bin/sync-it-all https://raw.githubusercontent.com/mohammadxali/sync-it-all/main/sync-it-all.sh sudo chmod +x /usr/local/bin/sync-it-all
-
Verify Installation:
Check that the script is available globally:
sync-it-all --help
To synchronize all repositories in a specified directory:
sync-it-all <directory>
<directory>
: The path to the directory containing Git repositories to synchronize.
Sync all repositories in the example
directory:
sync-it-all example
Sync all repositories in the current directory:
sync-it-all .
To enable logging, use the --with-logs
flag. This creates a timestamped .log
file in the target directory.
sync-it-all <directory> --with-logs
Sync all repositories in the example
directory and generate a log file:
sync-it-all example --with-logs
If logging is enabled, the script creates a log file with a name like sync-log_<directory-name>_<timestamp>.log
in the target directory. The log file contains details about the synchronization process, including any errors encountered.
-
Stashing Uncommitted Changes:
- The script stashes any uncommitted changes before switching branches to ensure the workspace is clean.
-
Branch Checkouts:
- Attempts to switch to the
main
branch first. Ifmain
doesn't exist, it falls back tomaster
.
- Attempts to switch to the
-
Pull Changes:
- Once on the correct branch, it pulls the latest changes using
git pull --rebase
.
- Once on the correct branch, it pulls the latest changes using
--with-logs
: Generate a.log
file for the sync operation. Includes timestamps and repository details.--help
: Display the help message and exit.