git-worktreeinclude
git-worktreeinclude safely applies ignored files listed in .worktreeinclude from a source worktree to the current worktree.
Quickstart
Install (Homebrew)
brew tap satococoa/tap
brew install satococoa/tap/git-worktreeinclude
Build
go build -o git-worktreeinclude ./cmd/git-worktreeinclude
To use the Git extension form (git worktreeinclude ...), place git-worktreeinclude on your PATH.
Apply
git-worktreeinclude apply --from auto
Or via Git extension:
git worktreeinclude apply --from auto
Omitting the subcommand is equivalent to apply:
git-worktreeinclude --from auto
.worktreeinclude semantics
- Place
.worktreeinclude at the source worktree root (for --from auto, this is typically the main worktree).
- Format is gitignore-compatible (
# comments, blank lines, ! negation, / anchors, **, etc.).
.worktreeinclude may 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
Tracked files are never copied, even if listed in .worktreeinclude.
Example:
.env
.env.*
!.env.example
.vscode/settings.json
.idea/
Commands
git-worktreeinclude apply
Uses 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 main worktree automatically
--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
.worktreeinclude is a no-op success (exit code 0)
git-worktreeinclude doctor
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
git-worktreeinclude hook path
Prints the hooks directory path while respecting core.hooksPath.
git-worktreeinclude hook path [--absolute]
git-worktreeinclude hook print post-checkout
Prints the recommended post-checkout hook snippet.
git-worktreeinclude hook print post-checkout
JSON output
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": ".vscode/settings.json", "status": "same"},
{"op": "conflict", "path": ".env.local", "status": "diff"}
]
}
path is 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 --from auto --json
- Evaluate success by exit code
- Use JSON
summary and actions for details
post-checkout auto-apply (manual setup)
This project does not auto-install hooks. Use manual setup.
Shared hooks (recommended)
mkdir -p .githooks
git-worktreeinclude hook print post-checkout > .githooks/post-checkout
chmod +x .githooks/post-checkout
git config core.hooksPath .githooks
Generated post-checkout:
#!/bin/sh
set -eu
old="$1"
if [ "$old" = "0000000000000000000000000000000000000000" ]; then
git worktreeinclude apply --from auto --quiet || true
fi
- Runs only for newly created worktree/clone-style checkouts (
old is 40 zeros)
- Failure is non-fatal to avoid breaking checkout workflow
Existing hook managers (husky, etc.)
- Do not overwrite existing
post-checkout; append the if block.
- If
core.hooksPath is already configured, add the hook within that convention.
Notes:
git worktree add --no-checkout may not trigger post-checkout.
- In that case, run
git worktreeinclude apply --from auto manually.
Exit codes
0: success
1: internal error
2: argument error
3: conflict (apply)
4: environment/prerequisite error
Troubleshooting
not inside a git repository: run from a Git repository
source and target are not from the same repository: verify --from points to the same repo worktree
- conflict exit: use
--force or resolve target differences first
- no-op due to missing include: verify
.worktreeinclude exists 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)
Development
make fmt
make check-fmt
make vet
make lint
make test
make test-race
make ci
CI runs on pull requests and pushes to main via GitHub Actions.
golangci-lint is used with its default configuration (no .golangci.yml).
License
MIT. See LICENSE.