Last active
July 24, 2024 10:43
-
-
Save engineering87/68a204b08b02f6e58d6287165acbce9a to your computer and use it in GitHub Desktop.
Simple bash script for recursive git updating of local repositories
This file contains hidden or 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 | |
# Function to perform git pull on a directory if it contains a git repository | |
update_repository() { | |
if [ -d "$1/.git" ]; then | |
echo "Update repository in $1" | |
cd "$1" && git pull && cd - > /dev/null | |
else | |
echo "The $1 directory does not contain a Git repository" | |
fi | |
} | |
# Function to find and update top-level git repositories in a directory | |
find_repository() { | |
for dir in "$1"/*/ ; do | |
if [ -d "$dir" ]; then | |
update_repository "$dir" | |
fi | |
done | |
} | |
# The directory from which the script is launched | |
current_dir=$(pwd) | |
# Searches all top-level directories in the parent directory | |
parent_dir=$(dirname "$current_dir") | |
for dir in "$parent_dir"/*/ ; do | |
if [ -d "$dir" ]; then | |
find_repository "$dir" | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment