Created
January 28, 2026 01:59
-
-
Save bcantoni/4ff857355c66b18bb3d8292f5042b3f9 to your computer and use it in GitHub Desktop.
Update all git repos one level under the current directory
This file contains hidden or 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 | |
| # 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" |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Credit: My idea plus Claude Code :)