Skip to content

Instantly share code, notes, and snippets.

@martinamps
Created January 13, 2025 07:01
Show Gist options
  • Save martinamps/e082031f26337350826b48b5d7f7f34c to your computer and use it in GitHub Desktop.
Save martinamps/e082031f26337350826b48b5d7f7f34c to your computer and use it in GitHub Desktop.
verify all code repos are up to date with your git remote
#!/bin/zsh
CODE_DIR=~/code
for dir in $CODE_DIR/*; do
if [ -d "$dir" ]; then
echo "Checking: $dir"
if [ -d "$dir/.git" ]; then
cd "$dir"
REMOTE=$(git remote -v | grep fetch | awk '{print $2}')
if [ -z "$REMOTE" ]; then
echo " ❌ No remote configured."
else
echo " ✅ Remote configured: $REMOTE"
git fetch --quiet
LOCAL=$(git rev-parse HEAD)
UPSTREAM=$(git rev-parse @{u} 2>/dev/null)
if [ "$LOCAL" = "$UPSTREAM" ]; then
echo " ✅ Up to date with remote."
else
echo " ❌ Not up to date with remote."
fi
fi
else
echo " ❌ Not a Git repository."
fi
echo ""
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment