BASH
Batch Git Pull for Multiple Repositories
Automate updating all your local Git repositories with a single Bash script, navigating directories and executing `git pull` for a streamlined workflow.
#!/bin/bash
BASE_DIR="/path/to/your/projects" # Root directory containing all your git repos
# E.g., /path/to/your/projects/repo1, /path/to/your/projects/repo2
echo "Starting Git pull for all repositories under $BASE_DIR..."
# Find all .git directories and then get their parent directory
find "$BASE_DIR" -maxdepth 3 -type d -name ".git" | while read git_dir; do
repo_dir=$(dirname "$git_dir")
echo -e "
--- Pulling in $repo_dir ---"
(cd "$repo_dir" && git pull --rebase) # Use --rebase for cleaner history, or remove for merge
if [ $? -ne 0 ]; then
echo "Error pulling in $repo_dir" >&2
fi
done
echo -e "
All repository pulls attempted."
How it works: This script automates the process of updating multiple Git repositories. It defines a BASE_DIR where all repositories are located. It then uses `find` to locate all .git directories within a certain depth, extracts their parent directory (which is the repository root), and then `cd`s into each repository directory. Inside each repository, it executes `git pull --rebase` to fetch and integrate the latest changes from the remote, ensuring all your local development environments are up-to-date.