Skip to content

Instantly share code, notes, and snippets.

@bastosmichael
Last active September 27, 2023 13:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bastosmichael/07bf847496e3f88c5606265182461e56 to your computer and use it in GitHub Desktop.
Save bastosmichael/07bf847496e3f88c5606265182461e56 to your computer and use it in GitHub Desktop.
Automated Git Update for Sub-Directories
#!/bin/bash
# Get the current directory from which the script is executed
DIR="$(pwd)"
# Iterate over sub-directories
for SUB_DIR in "$DIR"/*; do
if [ -d "$SUB_DIR" ]; then
echo "Processing $SUB_DIR..."
# Navigate to sub-directory
cd "$SUB_DIR"
# Check if directory is a git repository
if [ -d ".git" ]; then
# Checkout main branch
git checkout main
# Fetch updates
git fetch
# Fetch main updates
git pull origin main
# Confirm that the latest changes have been fetched
echo "$SUB_DIR is now up to date!"
else
echo "$SUB_DIR is not a git repository. Skipping..."
fi
# Go back to the original directory to continue the loop
cd "$DIR"
fi
done
echo "All sub-directories processed!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment