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.
git for-each-repo --config=<key> [--keep-going] <git-command> [<args>...]
Try it
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.
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
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 lsdoes not work; the words after the key are passed togit. 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-toplevelfirst, 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 registerappends the current repository tomaintenance.repoin your global config, andgit maintenance runuses this same mechanism to visit every registered repository. - Unrelated to submodules.
git submodule foreachwalks the submodules of one repository;for-each-repowalks arbitrary repositories you listed. - Be careful with writes. Running
pull,gcorpushacross many repositories is convenient but hard to undo. Try a read-only command likestatusfirst.