Skip to content

Instantly share code, notes, and snippets.

@Vitexus
Created August 14, 2025 13:56
Show Gist options
  • Select an option

  • Save Vitexus/8862f367213dbe0d4be0ff83a76f79ea to your computer and use it in GitHub Desktop.

Select an option

Save Vitexus/8862f367213dbe0d4be0ff83a76f79ea to your computer and use it in GitHub Desktop.
Recursive Pull for PHP projects
#!/bin/bash
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
WHITE='\033[1;37m'
NC='\033[0m' # No Color
success_projects=()
failed_projects=()
# Find all git repos
while IFS= read -r -d '' gitdir; do
project_dir="$(dirname "$gitdir")"
project_name="$(basename "$project_dir")"
# Remove composer.lock if exists
if [ -f "$project_dir/composer.lock" ]; then
rm "$project_dir/composer.lock"
fi
# Pull latest changes, handle divergent branches
pull_output=$(cd "$project_dir" && git pull 2>&1)
if echo "$pull_output" | grep -q "fatal: Need to specify how to reconcile divergent branches"; then
# Retry with --rebase
pull_output=$(cd "$project_dir" && git pull --rebase 2>&1)
fi
# Run composer update if composer.json exists
if [ -f "$project_dir/composer.json" ]; then
(cd "$project_dir" && composer update)
if [ $? -eq 0 ]; then
success_projects+=("$project_dir|$project_name")
else
failed_projects+=("$project_dir|$project_name")
fi
fi
done < <(find . -type d -name .git -print0)
# Print results
echo -e "\nUpdate results:"
for entry in "${success_projects[@]}"; do
path="${entry%%|*}"
name="${entry##*|}"
echo -e "${WHITE}$path${NC} ${GREEN}$name${NC}"
done
for entry in "${failed_projects[@]}"; do
path="${entry%%|*}"
name="${entry##*|}"
echo -e "${WHITE}$path${NC} ${RED}$name${NC}"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment