Skip to content
DevOps AI ToolKit
Newsletter
All prompts
AI for Bash & Python Automation Difficulty: Intermediate ClaudeChatGPTCursor

Bash Multi-Repo Git Bulk Command Runner Prompt

Build a Bash script that runs the same git or shell command across many local repositories with per-repo isolation, dirty-tree guards, and an aggregated pass/fail summary

Target user
engineers who automate ops with Bash and Python
Difficulty
Intermediate
Tools
Claude, ChatGPT, Cursor

The prompt

You are an automation engineer who maintains dozens of related git repositories and needs to run the same operation (pull, checkout, status, or an arbitrary command) across all of them safely.

I will provide:
- A directory (or list) of repo paths to iterate over
- The command to run in each repo (git or arbitrary shell)
- Rules for what should block a repo — e.g. skip repos with uncommitted changes, or only act on a given branch

Your job:

1. **Discover repos** — find directories containing `.git` under the root, and iterate deterministically (sorted), skipping non-repos.
2. **Isolate each run** — run each repo in a subshell so a `cd` or failure in one never leaks into the next, and never let one repo's non-zero exit abort the whole loop.
3. **Guard destructive actions** — before pull/checkout/reset, check `git status --porcelain`; skip (and record) any repo with a dirty working tree unless an explicit `--force` is passed. Detect the current branch and honor a `--branch` filter.
4. **Capture per-repo output** — collect stdout/stderr, exit code, and elapsed time for each repo without interleaving output from parallel runs.
5. **Optional parallelism** — offer a bounded-concurrency mode (e.g. via `xargs -P` or background jobs with a job cap) while keeping output attributable to each repo.
6. **Summarize** — print an aligned table of repo → status (OK / SKIPPED / FAILED) at the end and exit non-zero if any repo failed.

Output as: the full script (`set -euo pipefail`) in one fenced block, then example invocations for status-all, guarded-pull-all, and running an arbitrary command.

Default to read-only and skip-dirty behavior; require an explicit flag before any command that can lose local work.

Run this prompt with AI

Test it, get an AI-improved version, or compare models — live in the Prompt Workspace. No copy-paste.

Related prompts

More Bash & Python Automation prompts & error guides

Browse every Bash & Python Automation prompt and troubleshooting guide in one place.

Free download · 368-page PDF

Reading prompts? Get all 500 in one free PDF

500 battle-tested, copy-paste AI prompts engineered by a senior systems engineer — every one with fill-in placeholders and safety/back-out notes. Drop your email and it's yours.

  • 500 prompts: Linux · Kubernetes · Terraform · OpenStack · GitLab · Docker · Monitoring · Incident Response
  • Instant PDF download — yours free, forever
  • Plus one practical AI-workflow email a week (no spam)

Single opt-in · unsubscribe anytime · no spam.