Created
August 5, 2024 12:22
-
-
Save kornysietsma/b35101c76571b941b641c6180af69d05 to your computer and use it in GitHub Desktop.
simple script to update all git repos in child 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 -e | |
RED='\033[0;31m' | |
GREEN='\033[0;33m' | |
NC='\033[0m' | |
for dir in */; do | |
echo "processing $dir" | |
cd "$dir" || continue | |
if [ -d ".git" ]; then | |
status=$(git status -s | { grep -v "^?? " || true; } ) | |
if [ -n "$status" ]; then | |
echo -e "${RED}$dir has uncommitted changes --skipping${NC}" | |
else | |
git fetch -q | |
incoming_changes=$(git rev-list --count "..@{u}") | |
echo -e "Pulling ${GREEN}$incoming_changes${NC} changes" | |
git --no-pager log --pretty=format:"%h%x09%an%x09%ad%x09%s" --date=short "..@{u}" | |
git pull --ff-only || rc="$?" | |
if [ -n "$rc" ]; then | |
echo -e "${RED}$dir fast forward failed: ${rc} ${NC}"; | |
fi | |
fi | |
else | |
echo "$dir is not a git repository" | |
fi | |
cd .. | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment