Skip to content

Instantly share code, notes, and snippets.

@bcantoni
Created January 28, 2026 01:59
Show Gist options
  • Select an option

  • Save bcantoni/4ff857355c66b18bb3d8292f5042b3f9 to your computer and use it in GitHub Desktop.

Select an option

Save bcantoni/4ff857355c66b18bb3d8292f5042b3f9 to your computer and use it in GitHub Desktop.
Update all git repos one level under the current directory
#!/bin/bash
# Update all git repos one level under the current directory
start_dir="$(pwd)"
for dir in */; do
cd "$start_dir/$dir" || continue
# Skip if not a git repo
if [[ ! -d .git ]]; then
continue
fi
repo_name="${dir%/}"
remote_url=$(git remote get-url origin 2>/dev/null || echo "(no remote)")
echo "----------------------------------------"
echo "Repo: $repo_name"
echo "Origin: $remote_url"
echo ""
git fetch --all --quiet
pull_output=$(git pull 2>&1)
pull_status=$?
if [[ $pull_status -eq 0 ]]; then
echo "$pull_output"
else
if echo "$pull_output" | grep -q "local changes\|uncommitted changes\|would be overwritten"; then
echo "Note: Cannot pull - you have local changes that would be overwritten."
echo " Commit or stash your changes first."
else
echo "Pull failed: $pull_output"
fi
fi
echo ""
done
cd "$start_dir"
@bcantoni
Copy link
Author

Credit: My idea plus Claude Code :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment