git-worktreeinclude safely applies ignored files listed in .worktreeinclude from a source worktree to the current worktree.
brew tap satococoa/tap
brew install satococoa/tap/git-worktreeincludego build -o git-worktreeinclude ./cmd/git-worktreeincludeTo use the Git extension form (git worktreeinclude ...), place git-worktreeinclude on your PATH.
Subcommands are explicit. Use git-worktreeinclude apply ....
git-worktreeinclude applyOr via Git extension:
git worktreeinclude apply- Place
.worktreeincludeat the source worktree root (by default, this is typically the main worktree selected by--from auto). - Format is gitignore-compatible (
#comments, blank lines,!negation,/anchors,**, etc.). .worktreeincludemay be tracked, untracked, or ignored; if the file exists in the source worktree, it is used.- Actual sync target is the intersection of:
- Paths matching
.worktreeinclude - Paths Git classifies as ignored
- Paths matching
Tracked files are never copied, even if listed in .worktreeinclude.
Example for a typical app repo with local env, editor settings, and tool-specific cache:
.env
.env.local
!.env.example
.vscode/settings.json
.mise.local.toml
turbo/.cache/Print the installed version.
git-worktreeinclude --version
git-worktreeinclude -vUses the current worktree as target and copies from source worktree.
git-worktreeinclude apply [--from auto|<path>] [--include <path>] [--dry-run] [--force] [--json] [--quiet] [--verbose]--from:auto(default) chooses the first non-bare worktree fromgit worktree list --porcelain -z(typically the main worktree)--include: include file path (default:.worktreeinclude)- relative path: resolved from source worktree root only
- absolute path: must be inside source worktree root
--dry-run: plan only, make no changes--force: overwrite differing target files--json: emit a single JSON object to stdout--quiet: suppress human-readable output--verbose: print additional details
Safe defaults:
- Never touches tracked files
- Never deletes files
- Never overwrites by default (differences become conflicts, exit code
3) - Missing source
.worktreeincludeis a no-op success (exit code0)
Diagnostic command. Produces a dry-run style summary.
git-worktreeinclude doctor [--from auto|<path>] [--include <path>] [--quiet] [--verbose]Shows:
- target repository root
- source selection result
- include file status and pattern count
- source include path resolution
- no-op reason when include file is missing in source
- matched / copy planned / conflicts / missing source / skipped same / errors
apply --json emits a single JSON object to stdout.
{
"from": "/abs/path/source",
"to": "/abs/path/target",
"include_file": ".worktreeinclude",
"summary": {
"matched": 12,
"copied": 8,
"skipped_same": 3,
"skipped_missing_src": 1,
"conflicts": 0,
"errors": 0
},
"actions": [
{"op": "copy", "path": ".env", "status": "done"},
{"op": "skip", "path": ".mise.local.toml", "status": "same"},
{"op": "conflict", "path": ".vscode/settings.json", "status": "diff"}
]
}pathis repo-root relative and slash-separated- File contents and secrets are never output
Run this immediately after creating a worktree:
git worktree add <path> -b <branch>
git -C <path> worktreeinclude apply --json- Evaluate success by exit code
- Use JSON
summaryandactionsfor details
0: success1: internal error2: argument/usage error3: conflict (apply) or unknown help topic4: environment/prerequisite error
not inside a git repository: run from a Git repositorysource and target are not from the same repository: verify--frompoints to the same repo worktree- conflict exit: use
--forceor resolve target differences first - no-op due to missing include: verify
.worktreeincludeexists in the source worktree selected by--from - if include exists only in target: copy that file to source worktree (or run with a different
--from)
make fmt
make check-fmt
make vet
make lint
make test
make test-race
make ciCI runs on pull requests and pushes to main via GitHub Actions.
golangci-lint is used with its default configuration (no .golangci.yml).
make lint installs a pinned golangci-lint binary into .cache/bin on first run, so the first run needs network access to fetch the tool.
MIT. See LICENSE.