Skip to content

Instantly share code, notes, and snippets.

@engineering87
Last active July 24, 2024 10:43
Show Gist options
  • Save engineering87/68a204b08b02f6e58d6287165acbce9a to your computer and use it in GitHub Desktop.
Save engineering87/68a204b08b02f6e58d6287165acbce9a to your computer and use it in GitHub Desktop.
Simple bash script for recursive git updating of local repositories
#!/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