Skip to content
Tutorials Center
My learning

Topics

Git Reference ยท Plumbing Commands

git for-each-repo command

Reference for git for-each-repo: run one Git command in every repository listed under a multi-valued config key, with --config, --keep-going and examples.

git for-each-repo runs the same Git command in several repositories. It does not search the disk. Instead you name a configuration key, and every value of that key is treated as the path of a repository. For each path Git runs git -C <path> <command> in turn.

The command exists mainly for git maintenance, which keeps its list of registered repositories in the multi-valued key maintenance.repo. You can use it for your own lists too, for example to fetch every project you track with one line.

Terminal
git for-each-repo --config=<key> [--keep-going] <git-command> [<args>...]

Try it

Bash Run status in two repositories

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.

Bash Failures and the --keep-going flag

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.

Syntax

Terminal
git for-each-repo --config=<key> <git-command> [<args>...]
git for-each-repo --config=<key> --keep-going <git-command> [<args>...]
Name Description
--config=<key> Required. The configuration key whose values (all of them, from every config file) are repository paths.
--keep-going Continue with the remaining repositories if one fails. The final exit status is still nonzero. Added in Git 2.45.
<git-command> A Git subcommand and its arguments. It is run as git -C <path> <git-command> ..., so it must be a Git command, not an arbitrary program.

Exit status: 0 if the command succeeded everywhere. Without --keep-going the run stops at the first repository where the command fails and returns that failure.

Edge cases: if the key is not set at all, nothing runs and the command succeeds. Order follows the order of the values as the configuration is read (system, then global, then local files).

Usage notes

  • Only Git commands. git for-each-repo --config=x ls does not work; the words after the key are passed to git. Wrap other work in a Git alias that starts with ! if you need a shell command.
  • Output is not labelled. Git does not print which repository produced which line. Include the path yourself, for example by using rev-parse --show-toplevel first, or run a command that prints its own context.
  • Paths must be absolute or resolvable from the directory where you run the command. Prefer absolute paths in the list.
  • Registering repositories. git maintenance register appends the current repository to maintenance.repo in your global config, and git maintenance run uses this same mechanism to visit every registered repository.
  • Unrelated to submodules. git submodule foreach walks the submodules of one repository; for-each-repo walks arbitrary repositories you listed.
  • Be careful with writes. Running pull, gc or push across many repositories is convenient but hard to undo. Try a read-only command like status first.