Skip to content

git worktree-exec

Run a command across one or more worktrees

TIP

This command is also available as daft exec. See daft exec.

Description

Runs one or more commands against one or more selected worktrees without changing the current directory.

Targets may be given as positional branch or worktree-directory names, or globs against branch names (e.g. 'feat/*'). Use --all to target every worktree in the repository. Positionals and --all are mutually exclusive.

Commands are expressed either as a literal argv after --, or as one or more -x shell strings. The two forms are mutually exclusive. Multiple -x values run sequentially per worktree; a failure stops that worktree but does not stop other worktrees.

When a single worktree is targeted, stdio is fully inherited, making interactive programs (claude, vim, fzf) work the same as if you had cd'd into the worktree first.

By default, captured stdout/stderr is dumped only for failed or cancelled worktrees. Pass --show-output to dump it for successful worktrees too. The flag has no effect on single-target runs (stdio is already inherited).

Usage

git worktree-exec [OPTIONS] [TARGETS] [CMD]

Arguments

ArgumentDescriptionRequired
<TARGETS>Target worktree(s) by branch name, directory name, or globNo
<CMD>Trailing command vector after --. Mutually exclusive with -xNo

Options

OptionDescriptionDefault
--allTarget every worktree in the repository
-x, --exec <CMD>Shell command to run (repeatable); runs via $SHELL -c
--sequentialRun worktrees one at a time and stop on first failure
--keep-goingRun worktrees one at a time and continue through failures
--refresh-aliasesRe-capture user shell aliases instead of using the cached snapshot
--show-outputDump captured stdout/stderr for successful worktrees too (no-op for single-target runs)

Global Options

OptionDescription
-h, --helpPrint help information
-V, --versionPrint version information

See Also

Released under MIT or Apache-2.0.