Last active
September 27, 2023 13:38
-
-
Save bastosmichael/07bf847496e3f88c5606265182461e56 to your computer and use it in GitHub Desktop.
Automated Git Update for Sub-Directories
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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