Build Px4 macOS
PX4/PX4-Autopilot
Build PX4 board firmware on macOS in the px4-dev Docker container, including git worktrees, and stage commit-labeled artifacts without flashing hardware.
A skill your agent uses when working on multiple branches simultaneously, context switching without stashing, reviewing PRs while developing, testing in isolation, or comparing implementations…
$ npx skills add NeoLabHQ/context-engineering-kit --skill git-worktrees -a claude-codeProject install by default; add -g for ~/.claude/skills/.
$ gh skill install NeoLabHQ/context-engineering-kit git-worktrees --agent claude-codeProject scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).
$ git clone --depth 1 https://github.com/NeoLabHQ/context-engineering-kit.git skills-src && mkdir -p .claude/skills && cp -r skills-src/skills/git-worktrees .claude/skills/git-worktrees && rm -rf skills-srcUse ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.
Claude Code skills documentation · loads skills from .claude/skills/
Install the "git-worktrees" agent skill from https://github.com/NeoLabHQ/context-engineering-kit/tree/master/skills/git-worktrees into .claude/skills/git-worktrees/ in this project. Copy the whole folder (SKILL.md and every file beside it), keep the folder name "git-worktrees", then confirm the skill loads.Claude Code copies the folder itself, the same result as the manual copy. Check what it changed before you commit it.
$skill-installer install https://github.com/NeoLabHQ/context-engineering-kit/tree/master/skills/git-worktreesType this inside Codex. $skill-installer <name> installs a curated skill from openai/skills. The installer writes to $CODEX_HOME/skills (default ~/.codex/skills). Restart Codex if the skill does not show up.
$ npx skills add NeoLabHQ/context-engineering-kit --skill git-worktrees -a codexProject install goes to .agents/skills/; add -g for ~/.codex/skills/.
$ gh skill install NeoLabHQ/context-engineering-kit git-worktrees --agent codexProject scope by default (.agents/skills/); add --scope user for a personal install.
$ git clone --depth 1 https://github.com/NeoLabHQ/context-engineering-kit.git skills-src && mkdir -p .agents/skills && cp -r skills-src/skills/git-worktrees .agents/skills/git-worktrees && rm -rf skills-srcUse ~/.agents/skills/ instead of .agents/skills for a personal install.
Codex skills documentation · loads skills from .agents/skills/
Install the "git-worktrees" agent skill from https://github.com/NeoLabHQ/context-engineering-kit/tree/master/skills/git-worktrees into .agents/skills/git-worktrees/ in this project. Copy the whole folder (SKILL.md and every file beside it), keep the folder name "git-worktrees", then confirm the skill loads.Codex copies the folder itself, the same result as the manual copy. Check what it changed before you commit it.
$ npx skills add NeoLabHQ/context-engineering-kit --skill git-worktrees -a cursorProject install goes to .agents/skills/; add -g for ~/.cursor/skills/.
$ gh skill install NeoLabHQ/context-engineering-kit git-worktrees --agent cursorProject scope by default (.agents/skills/); add --scope user for a personal install.
$ git clone --depth 1 https://github.com/NeoLabHQ/context-engineering-kit.git skills-src && mkdir -p .cursor/skills && cp -r skills-src/skills/git-worktrees .cursor/skills/git-worktrees && rm -rf skills-srcUse ~/.cursor/skills/ instead of .cursor/skills for a personal install.
Cursor skills documentation · loads skills from .cursor/skills/, .agents/skills/, .claude/skills/, .codex/skills/
Install the "git-worktrees" agent skill from https://github.com/NeoLabHQ/context-engineering-kit/tree/master/skills/git-worktrees into .cursor/skills/git-worktrees/ in this project. Copy the whole folder (SKILL.md and every file beside it), keep the folder name "git-worktrees", then confirm the skill loads.Cursor copies the folder itself, the same result as the manual copy. Check what it changed before you commit it.
$ gemini skills install https://github.com/NeoLabHQ/context-engineering-kit.git --path skills/git-worktrees--scope user (default) or --scope workspace; --path is the subfolder of the repo that holds the skill; --consent skips the security confirmation prompt.
$ npx skills add NeoLabHQ/context-engineering-kit --skill git-worktrees -a gemini-cliProject install goes to .agents/skills/; add -g for ~/.gemini/skills/.
$ gh skill install NeoLabHQ/context-engineering-kit git-worktrees --agent gemini-cliProject scope by default (.agents/skills/); add --scope user for a personal install.
$ git clone --depth 1 https://github.com/NeoLabHQ/context-engineering-kit.git skills-src && mkdir -p .gemini/skills && cp -r skills-src/skills/git-worktrees .gemini/skills/git-worktrees && rm -rf skills-srcUse ~/.gemini/skills/ instead of .gemini/skills for a personal install, then run /skills reload.
Gemini CLI skills documentation · loads skills from .gemini/skills/, .agents/skills/
Install the "git-worktrees" agent skill from https://github.com/NeoLabHQ/context-engineering-kit/tree/master/skills/git-worktrees into .gemini/skills/git-worktrees/ in this project. Copy the whole folder (SKILL.md and every file beside it), keep the folder name "git-worktrees", then confirm the skill loads.Gemini CLI copies the folder itself, the same result as the manual copy. Check what it changed before you commit it.
$ gh skill install NeoLabHQ/context-engineering-kit git-worktreesInstalls for Copilot at project scope by default; add --scope user for a personal install. Preview a skill first with gh skill preview. Needs GitHub CLI 2.90.0 or later (public preview).
$ npx skills add NeoLabHQ/context-engineering-kit --skill git-worktrees -a github-copilotProject install goes to .agents/skills/; add -g for ~/.copilot/skills/.
$ git clone --depth 1 https://github.com/NeoLabHQ/context-engineering-kit.git skills-src && mkdir -p .github/skills && cp -r skills-src/skills/git-worktrees .github/skills/git-worktrees && rm -rf skills-srcUse ~/.copilot/skills/ instead of .github/skills for a personal install. Commit .github/skills so cloud agent and code review can use it.
GitHub Copilot skills documentation · loads skills from .github/skills/, .claude/skills/, .agents/skills/
Install the "git-worktrees" agent skill from https://github.com/NeoLabHQ/context-engineering-kit/tree/master/skills/git-worktrees into .github/skills/git-worktrees/ in this project. Copy the whole folder (SKILL.md and every file beside it), keep the folder name "git-worktrees", then confirm the skill loads.GitHub Copilot copies the folder itself, the same result as the manual copy. Check what it changed before you commit it.
$ npx skills add NeoLabHQ/context-engineering-kit --skill git-worktrees -a opencodeOpenCode documents no install command of its own. Project install goes to .agents/skills/; add -g for ~/.config/opencode/skills/.
$ gh skill install NeoLabHQ/context-engineering-kit git-worktrees --agent opencodeProject scope by default (.agents/skills/); add --scope user for a personal install.
$ git clone --depth 1 https://github.com/NeoLabHQ/context-engineering-kit.git skills-src && mkdir -p .opencode/skills && cp -r skills-src/skills/git-worktrees .opencode/skills/git-worktrees && rm -rf skills-srcUse ~/.config/opencode/skills/ instead of .opencode/skills for a personal install.
OpenCode skills documentation · loads skills from .opencode/skills/, .claude/skills/, .agents/skills/
Install the "git-worktrees" agent skill from https://github.com/NeoLabHQ/context-engineering-kit/tree/master/skills/git-worktrees into .opencode/skills/git-worktrees/ in this project. Copy the whole folder (SKILL.md and every file beside it), keep the folder name "git-worktrees", then confirm the skill loads.OpenCode copies the folder itself, the same result as the manual copy. Check what it changed before you commit it.
git-worktreesA skill your agent uses when working on multiple branches simultaneously, context switching without stashing, reviewing PRs while developing, testing in isolation, or comparing implementations…
Git Worktrees is an agent skill from NeoLabHQ/context-engineering-kit. Use when working on multiple branches simultaneously, context switching without stashing, reviewing PRs while developing, testing in isolation, or comparing implementations across branches - provides git worktree commands and workflow patterns for parallel development with multiple working directories.
Its SKILL.md is about 10k tokens, which your agent loads only when the skill is triggered. It is a single SKILL.md file with no bundled scripts.
It sits in Development, covering Git worktrees. It works with Git. The repository describes itself as: Hand-crafted Claude Code Skills focused on improving agent results quality. Compatible with OpenCode, Cursor, Antigravity, Gemini CLI, and others. Includes CodeRabbit open-source… The licence is GPL-3.0.
6 steps, taken from the first numbered list in SKILL.md.
Read from SKILL.md and the folder at commit 23e2428. It shows what the files ask for, not the result of running them.
Pre-approves nothing: there is no allowed-tools line, so your agent's usual permission prompts apply.
From allowed-tools in the SKILL.md frontmatter.
Shell commands in SKILL.md call:
gitnpmbunpnpmyarnFrom the folder's file list and the shell code blocks in SKILL.md.
No URLs in SKILL.md. Its commands use git, npm, pnpm and yarn, which can reach the network depending on how they are called.
From URLs in SKILL.md, links to its own repository left out.
Names no API keys, tokens, secrets or passwords.
From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.
Git Worktrees loads about 10k tokens when it runs. Until then it costs about 79 tokens; SKILL.md has 3,311 words of instructions outside code blocks.
Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.
The automated check found no risky patterns in SKILL.md.
Automated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); files beside SKILL.md are not scanned.
The full file from NeoLabHQ/context-engineering-kit at commit 23e2428, republished under its GPL-3.0 licence (© NeoLabHQ). 3,311 words, ~10,373 tokens.
.claude/skills/git-worktrees/SKILL.md (or your agent's skills folder).Git worktrees enable checking out multiple branches simultaneously in separate directories, all sharing the same repository. Create a worktree instead of stashing changes or cloning separately.
Core principle: One worktree per active branch. Switch contexts by changing directories, not branches.
| Concept | Description |
|---|---|
| Main worktree | Original working directory from git clone or git init |
| Linked worktree | Additional directories created with git worktree add |
Shared .git | All worktrees share same Git object database (no duplication) |
| Branch lock | Each branch can only be checked out in ONE worktree at a time |
| Worktree metadata | Administrative files in .git/worktrees/ tracking linked worktrees |
| Task | Command |
|---|---|
| Create worktree (existing branch) | git worktree add <path> <branch> |
| Create worktree (new branch) | git worktree add -b <branch> <path> |
| Create worktree (new branch from ref) | git worktree add -b <branch> <path> <start> |
| Create detached worktree | git worktree add --detach <path> <commit> |
| List all worktrees | git worktree list |
| Remove worktree | git worktree remove <path> |
| Force remove worktree | git worktree remove --force <path> |
| Move worktree | git worktree move <old> <new> |
| Lock worktree | git worktree lock <path> |
| Unlock worktree | git worktree unlock <path> |
| Prune stale worktrees | git worktree prune |
| Repair worktree links | git worktree repair |
| Compare files between worktrees | diff ../worktree-a/file ../worktree-b/file |
| Get one file from another branch | git checkout <branch> -- <path> |
| Get partial file changes | git checkout -p <branch> -- <path> |
| Cherry-pick a commit | git cherry-pick <commit> |
| Cherry-pick without committing | git cherry-pick --no-commit <commit> |
| Merge without auto-commit | git merge --no-commit <branch> |
# Create worktree with existing branch
git worktree add ../feature-x feature-x
# Create worktree with new branch from current HEAD
git worktree add -b new-feature ../new-feature
# Create worktree with new branch from specific commit
git worktree add -b hotfix-123 ../hotfix origin/main
# Create worktree tracking remote branch
git worktree add --track -b feature ../feature origin/feature
# Create worktree with detached HEAD (for experiments)
git worktree add --detach ../experiment HEAD~5# Simple list
git worktree list
# Verbose output with additional details
git worktree list -v
# Machine-readable format (for scripting)
git worktree list --porcelainExample output:
/home/user/project abc1234 [main]
/home/user/project-feature def5678 [feature-x]
/home/user/project-hotfix ghi9012 [hotfix-123]# Remove worktree (working directory must be clean)
git worktree remove ../feature-x
# Force remove (discards uncommitted changes)
git worktree remove --force ../feature-x# Relocate worktree to new path
git worktree move ../old-path ../new-path# Lock worktree (prevents pruning if on removable storage)
git worktree lock ../feature-x
git worktree lock --reason "On USB drive" ../feature-x
# Unlock worktree
git worktree unlock ../feature-x# Remove stale worktree metadata (after manual directory deletion)
git worktree prune
# Dry-run to see what would be pruned
git worktree prune --dry-run
# Verbose output
git worktree prune -v# Repair worktree links after moving directories manually
git worktree repair
# Repair specific worktree
git worktree repair ../feature-xTo fix a bug while feature work is in progress:
# Create worktree for hotfix from main
git worktree add -b hotfix-456 ../project-hotfix origin/main
# Switch to hotfix directory, fix, commit, push
cd ../project-hotfix
git add . && git commit -m "fix: resolve critical bug #456"
git push origin hotfix-456
# Return to feature work
cd ../project
# Clean up when done
git worktree remove ../project-hotfixTo review a PR without affecting current work:
# Fetch PR branch and create worktree
git fetch origin pull/123/head:pr-123
git worktree add ../project-review pr-123
# Review: run tests, inspect code
cd ../project-review
# Return to work, then clean up
cd ../project
git worktree remove ../project-review
git branch -d pr-123To compare code across branches side-by-side:
# Create worktrees for different versions
git worktree add ../project-v1 v1.0.0
git worktree add ../project-v2 v2.0.0
# Diff, compare, or run both simultaneously
diff ../project-v1/src/module.js ../project-v2/src/module.js
# Clean up
git worktree remove ../project-v1
git worktree remove ../project-v2To run tests/builds in isolation while continuing development:
# Create worktree for CI-like testing
git worktree add ../project-test main
# Start long-running tests in background
cd ../project-test && npm test &
# Continue development in main worktree
cd ../projectTo maintain a clean main checkout for reference:
# Create permanent worktree for main branch
git worktree add ../project-main main
# Lock to prevent accidental removal
git worktree lock --reason "Reference checkout" ../project-mainTo combine specific changes from multiple feature branches:
# Create worktrees for each feature to review
git worktree add ../project-feature-1 feature-1
git worktree add ../project-feature-2 feature-2
# Review changes in each worktree
diff ../project/src/module.js ../project-feature-1/src/module.js
diff ../project/src/module.js ../project-feature-2/src/module.js
# From main worktree, selectively take changes
cd ../project
git checkout feature-1 -- src/moduleA.js src/utils.js
git checkout feature-2 -- src/moduleB.js
git commit -m "feat: combine selected changes from feature branches"
# Or cherry-pick specific commits
git cherry-pick abc1234 # from feature-1
git cherry-pick def5678 # from feature-2
# Clean up
git worktree remove ../project-feature-1
git worktree remove ../project-feature-2Since all worktrees share the same Git repository, you can compare files, cherry-pick commits, and selectively merge changes between them.
Since worktrees are just directories, you can compare files directly:
# Compare specific file between worktrees
diff ../project-main/src/app.js ../project-feature/src/app.js
# Use git diff to compare branches (works from any worktree)
git diff main..feature-branch -- src/app.js
# Visual diff with your preferred tool
code --diff ../project-main/src/app.js ../project-feature/src/app.js
# Compare entire directories
diff -r ../project-v1/src ../project-v2/srcYou can selectively bring a single file from another branch using git checkout:
# In your current branch, get a specific file from another branch
git checkout feature-branch -- path/to/file.js
# Or get it from a specific commit
git checkout abc1234 -- path/to/file.js
# Get multiple specific files
git checkout feature-branch -- src/module.js src/utils.jsFor partial file changes (specific hunks/lines only):
# Interactive patch mode - select which changes to take
git checkout -p feature-branch -- path/to/file.jsThis prompts you to accept/reject each change hunk individually with options:
y - apply this hunkn - skip this hunks - split into smaller hunkse - manually edit the hunkCherry-picking works at the commit level. Since all worktrees share the same repository, you can cherry-pick any commit:
# Find the commit hash (from any worktree or git log)
git log feature-branch --oneline
# Cherry-pick specific commit into your current branch
git cherry-pick abc1234
# Cherry-pick multiple commits
git cherry-pick abc1234 def5678
# Cherry-pick a range of commits
git cherry-pick abc1234^..def5678
# Cherry-pick without committing (stage changes only)
git cherry-pick --no-commit abc1234You can merge or cherry-pick from multiple branches:
# Merge multiple branches sequentially
git merge feature-1
git merge feature-2
# Or use octopus merge for multiple branches at once
git merge feature-1 feature-2 feature-3
# Cherry-pick commits from multiple branches
git cherry-pick abc1234 # from feature-1
git cherry-pick def5678 # from feature-2# Get specific files from different branches
git checkout feature-1 -- src/moduleA.js
git checkout feature-2 -- src/moduleB.js
git commit -m "Merge selected files from feature branches"# Select specific hunks from a file
git checkout -p feature-1 -- src/shared.js# Apply changes without committing
git cherry-pick --no-commit abc1234
# Unstage what you don't want
git reset HEAD -- unwanted-file.js
git checkout -- unwanted-file.js
# Commit only what you kept
git commit -m "Selected changes from feature-1"# Start merge but don't auto-commit
git merge --no-commit feature-1
# Review and modify staged changes
git status
git reset HEAD -- file-to-exclude.js
git checkout -- file-to-exclude.js
# Commit your selection
git commit -m "Merge selected changes from feature-1"# Restore specific file from another branch
git restore --source=feature-branch -- path/to/file.js
# Interactive restore with patch selection
git restore -p --source=feature-branch -- path/to/file.jsOrganize worktrees predictably:
~/projects/
myproject/ # Main worktree (main/master branch)
myproject-feature-x/ # Feature branch worktree
myproject-hotfix/ # Hotfix worktree
myproject-review/ # Temporary PR review worktreeNaming convention: <project>-<purpose> or <project>-<branch>
| Practice | Rationale |
|---|---|
| Use sibling directories | Keep worktrees at same level as main project for easy navigation |
| Name by purpose | project-review is clearer than project-pr-123 |
| Clean up promptly | Remove worktrees when done to avoid confusion |
| Lock remote worktrees | Prevent pruning if worktree is on network/USB storage |
Use --detach for experiments | Avoid creating throwaway branches |
| Commit before removing | Always commit or stash before git worktree remove |
Cause: Attempting to checkout a branch that's active in another worktree.
Solution:
# Find where the branch is checked out
git worktree list
# Either work in that worktree or remove it first
git worktree remove ../other-worktreeCause: Deleted worktree directory without using git worktree remove.
Solution:
# Clean up stale metadata
git worktree pruneCause: Moved worktree directory without using git worktree move.
Solution:
# Repair the worktree links
git worktree repair
# Or specify the new path
git worktree repair /new/path/to/worktreeCause: Worktree was on removable storage that's no longer connected.
Solution:
# If temporary, lock it to prevent pruning
git worktree lock ../usb-worktree
# If permanent, prune it
git worktree prune| Mistake | Fix |
|---|---|
Using rm -rf to delete worktree | Always use git worktree remove, then git worktree prune if needed |
| Forgetting branch is locked to worktree | Run git worktree list before checkout errors |
| Not cleaning up temporary worktrees | Remove worktrees immediately after task completion |
| Creating worktrees in nested locations | Use sibling directories (../project-feature) not subdirs |
| Moving worktree directory manually | Use git worktree move or run git worktree repair after |
To isolate parallel agent tasks:
# Create worktree for isolated task
git worktree add -b task-123 ../project-task-123
cd ../project-task-123
# Make changes, run tests, return
cd ../projectTo experiment safely with detached HEAD:
# Create detached worktree (no branch to clean up)
git worktree add --detach ../project-experiment
cd ../project-experiment
# Experiment, then discard or commit to new branch
git worktree remove --force ../project-experimentBefore using worktrees:
When creating worktrees:
--detach for experimentsWhen removing worktrees:
git worktree remove, not rm -rfgit worktree prune if directory was deleted manuallyWorkflow to compare files and directories between git worktrees, helping users understand differences in code across branches or worktrees.
CRITICAL: Perform the following steps exactly as described:
Current state check: Run git worktree list to show all existing worktrees and their locations
Parse user input: Classify each provided argument:
--stat: Show summary statistics of differences (files changed, insertions, deletions)git worktree listDetermine comparison targets (worktrees to compare):
a. If user provided worktree paths: Use those as comparison targets
b. If user specified branch names: Find the worktrees for those branches from git worktree list
c. If only one worktree exists besides current: Use current and that one as comparison targets
d. If multiple worktrees exist and none specified: Present list and ask user which to compare
e. If no other worktrees exist: Offer to compare with a branch using git diff
Determine what to compare (files/directories within worktrees): a. If user specified file(s) or directory(ies) paths: Compare ALL of them b. If no specific paths given: Ask user:
Execute comparison:
For specific files between worktrees:
diff <worktree1>/<path> <worktree2>/<path>
# Or for unified diff format:
diff -u <worktree1>/<path> <worktree2>/<path>For directories between worktrees:
diff -r <worktree1>/<directory> <worktree2>/<directory>
# Or for summary only:
diff -rq <worktree1>/<directory> <worktree2>/<directory>For branch-level comparison (using git diff):
git diff <branch1>..<branch2> -- <path>
# Or for stat summary:
git diff --stat <branch1>..<branch2>For comparing with current working directory:
diff <current-file> <other-worktree>/<file>Format and present results:
| Mode | Description | Command Pattern |
|---|---|---|
| File diff | Compare single file between worktrees | diff -u <wt1>/file <wt2>/file |
| Directory diff | Compare directories recursively | diff -r <wt1>/dir <wt2>/dir |
| Summary only | Show which files differ (no content) | diff -rq <wt1>/ <wt2>/ |
| Git diff | Use git's diff (branch-based) | git diff branch1..branch2 -- path |
| Stat view | Show change statistics | git diff --stat branch1..branch2 |
The command finds worktrees using git worktree list:
/home/user/project abc1234 [main]
/home/user/project-feature def5678 [feature-x]
/home/user/project-hotfix ghi9012 [hotfix-123]From this output, the command extracts:
Compare specific file between worktrees:
> /worktrees compare src/app.js
# Prompts to select which worktree to compare with
# Shows diff of src/app.js between current and selected worktreeCompare between two specific worktrees:
> /worktrees compare ../project-main ../project-feature src/module.js
# Compares src/module.js between the two specified worktreesCompare multiple files/directories:
> /worktrees compare src/app.js src/utils/ package.json
# Shows diffs for all three paths between worktreesCompare entire directories:
> /worktrees compare src/
# Shows all differences in src/ directory between worktreesGet summary statistics:
> /worktrees compare --stat
# Shows which files differ and line countsInteractive mode:
> /worktrees compare
# Lists available worktrees
# Asks which to compare
# Asks for specific paths or entire worktreeCompare with branch worktree by branch name:
> /worktrees compare feature-x
# Finds worktree for feature-x branch and comparesCompare specific paths between branch worktrees:
> /worktrees compare main feature-x src/ tests/
# Compares src/ and tests/ directories between main and feature-x worktreesFile Comparison Header:
Comparing: src/app.js
From: /home/user/project (main)
To: /home/user/project-feature (feature-x)
---
[diff output]Summary Output:
Worktree Comparison Summary
===========================
From: /home/user/project (main)
To: /home/user/project-feature (feature-x)
Files only in main:
- src/deprecated.js
Files only in feature-x:
+ src/new-feature.js
+ src/new-feature.test.js
Files that differ:
~ src/app.js
~ src/utils/helpers.js
~ package.json
Statistics:
3 files changed
2 files added
1 file removed# See what changed in a feature branch
> /worktrees compare --stat
> /worktrees compare src/components/# Compare how two features implemented similar functionality
> /worktrees compare ../project-feature-1 ../project-feature-2 src/auth/# Check if a specific file differs
> /worktrees compare package.json# Review all changes before merging (compare src and tests together)
> /worktrees compare --stat
> /worktrees compare src/ tests/
# Both src/ and tests/ directories will be comparedArgument detection: The command auto-detects argument types by comparing them against git worktree list output:
Multiple paths: When multiple file/directory paths are provided, ALL of them are compared between the selected worktrees (not just the first one).
Worktree paths: When specifying worktrees, use the full path or relative path from current directory (e.g., ../project-feature)
Branch vs Worktree: If you specify a branch name, the command looks for a worktree with that branch checked out. If no worktree exists for that branch, it suggests using git diff instead.
Large diffs: For large directories, the command will offer to show a summary first before displaying full diff output.
Binary files: Binary files are detected and reported as "Binary files differ" without showing actual diff.
File permissions: The diff will also show changes in file permissions if they differ.
No worktrees: If no other worktrees exist, the command will explain how to create one and offer to use git diff for branch comparison instead.
Use /worktrees create first to set up worktrees for comparison:
# Create worktrees for comparison
> /worktrees create feature-x, main
# Created: ../project-feature-x and ../project-main
# Now compare
> /worktrees compare src/"No other worktrees found"
/worktrees create <branch>git diff for branch-only comparison without worktrees"Worktree for branch not found"
git worktree list to see available worktrees/worktrees create <branch>"Path does not exist in worktree"
Workflow to create and setup git worktrees for parallel development, with automatic detection and installation of project dependencies.
CRITICAL: Perform the following steps exactly as described:
Current state check: Run git worktree list to show existing worktrees and git status to verify the repository state is clean (no uncommitted changes that might cause issues)
Fetch latest remote branches: Run git fetch --all to ensure local has knowledge of all remote branches
Parse user input: Determine what the user wants to create:
<name>: Create worktree with auto-detected type prefix--list: Just show existing worktrees and exitAuto-detect branch type from name: Check if the first word is a known branch type. If yes, use it as the prefix and the rest as the name. If no, default to feature/.
Known types: feature, feat, fix, bug, bugfix, hotfix, release, docs, test, refactor, chore, spike, experiment, review
Examples:
refactor auth system → refactor/auth-systemfix login bug → fix/login-bugauth system → feature/auth-system (default)hotfix critical error → hotfix/critical-errorName normalization: Convert spaces to dashes, lowercase, remove special characters except dashes/underscores
For each worktree to create: a. Branch name construction: Build full branch name from detected type and normalized name:
<prefix>/<normalized-name> (e.g., feature/auth-system)b. Branch resolution: Determine if the branch exists locally, remotely, or needs to be created:
git worktree add ../<project>-<name> <branch><branch>): git worktree add --track -b <branch> ../<project>-<name> origin/<branch>git worktree add -b <branch> ../<project>-<name> <base>c. Path convention: Use sibling directory with pattern ../<project-name>-<name>
feature/auth-system → ../myproject-auth-systemd. Create the worktree: Execute the appropriate git worktree add command
e. Dependency detection: Check the new worktree for dependency files and determine if setup is needed:
package.json -> Node.js project (npm/yarn/pnpm/bun)requirements.txt or pyproject.toml or setup.py -> Python projectCargo.toml -> Rust projectgo.mod -> Go projectGemfile -> Ruby projectcomposer.json -> PHP projectf. Package manager detection (for Node.js projects):
bun.lockb -> Use bun installpnpm-lock.yaml -> Use pnpm installyarn.lock -> Use yarn installpackage-lock.json or default -> Use npm installg. Automatic setup: Automatically run dependency installation:
Summary: Display summary of created worktrees:
cd <worktree-path>Worktrees are created as sibling directories to maintain organization:
~/projects/
myproject/ # Main worktree (current directory)
myproject-add-auth/ # Feature branch worktree (feature/add-auth)
myproject-critical-bug/ # Hotfix worktree (hotfix/critical-bug)
myproject-pr-456/ # PR review worktree (review/pr-456)Naming rules:
<project-name>-<name> (uses the name part, NOT the full branch)<type-prefix>/<name> (e.g., feature/add-auth)<name> portion for brevityFeature worktree (default):
> /worktrees create auth system
# Branch: feature/auth-system
# Creates: ../myproject-auth-systemFix worktree:
> /worktrees create fix login error
# Branch: fix/login-error
# Creates: ../myproject-login-errorRefactor worktree:
> /worktrees create refactor api layer
# Branch: refactor/api-layer
# Creates: ../myproject-api-layerHotfix worktree:
> /worktrees create hotfix critical bug
# Branch: hotfix/critical-bug
# Creates: ../myproject-critical-bugList existing worktrees:
> /worktrees list
# Shows: git worktree list outputNode.js project with pnpm:
Detected Node.js project with pnpm-lock.yaml
Installing dependencies with pnpm...
✓ Dependencies installed successfullyPython project:
Detected Python project with requirements.txt
Installing dependencies with pip...
✓ Dependencies installed successfullyRust project:
Detected Rust project with Cargo.toml
Building project with cargo...
✓ Project built successfully> /worktrees create new dashboard
# Branch: feature/new-dashboard
# Creates worktree, installs dependencies, ready to code# In main worktree, working on feature
> /worktrees create hotfix critical bug
# Branch: hotfix/critical-bug
# Creates separate worktree from main/master
# Fix bug in hotfix worktree
# Return to feature work when done> /worktrees create review pr 123
# Branch: review/pr-123
# Creates worktree for reviewing PR
# Can run tests, inspect code
# Delete when review complete> /worktrees create spike new architecture
# Branch: spike/new-architecture
# Creates isolated worktree for experimentation
# Discard or merge based on resultsBranch lock: Each branch can only be checked out in one worktree at a time. If a branch is already checked out, the command will inform you which worktree has it.
Shared .git: All worktrees share the same Git object database. Changes committed in any worktree are visible to all others.
Clean working directory: The command checks for uncommitted changes and warns if present, as creating worktrees is safest with a clean state.
Sibling directories: Worktrees are always created as sibling directories (using ../) to keep the workspace organized. Never create worktrees inside the main repository.
Automatic dependency installation: The command automatically detects the project type and package manager, then runs the appropriate install command without prompting.
Remote tracking: For remote branches, worktrees are created with proper tracking setup (--track flag) so pulls/pushes work correctly.
When done with a worktree, use the proper removal command:
git worktree remove ../myproject-add-authOr for a worktree with uncommitted changes:
git worktree remove --force ../myproject-add-authNever use rm -rf to delete worktrees - always use git worktree remove.
"Branch is already checked out"
git worktree list to see where the branch is checked out"Cannot create worktree - path already exists"
"Dependency installation failed"
cd ../myproject-<name>"Wrong type detected"
fix, hotfix, docs, test, refactor, chore, spike, reviewfeature/ when first word isn't a known typeWorkflow to help users merge changes from git worktrees into their current branch, supporting multiple merge strategies from simple file checkout to selective cherry-picking.
CRITICAL: Perform the following steps exactly as described:
Current state check: Run git worktree list to show all existing worktrees and git status to verify working directory state
Parse user input: Determine what merge operation the user wants:
--interactive or no arguments: Guided interactive mode--from <worktree>: Specify source worktree explicitly--patch or -p: Use interactive patch selection modeDetermine source worktree/branch:
a. If user specified --from <worktree>: Use that worktree path directly
b. If user specified a branch name: Find worktree for that branch from git worktree list
c. If only one other worktree exists: Ask to confirm using it as source
d. If multiple worktrees exist: Present list and ask user which to merge from
e. If no other worktrees exist: Explain and offer to use branch-based merge instead
Determine merge strategy: Present options based on user's needs:
Strategy A: Selective File Checkout (for specific files/directories)
git checkout <branch> -- <path>Strategy B: Interactive Patch Selection (for partial file changes)
git checkout -p <branch> -- <path>Strategy C: Cherry-Pick with Selective Staging (for specific commits)
git cherry-pick --no-commit <commit>git reset HEAD -- <unwanted-files> to unstagegit checkout -- <unwanted-files> to discardgit commit -m "message"Strategy D: Manual Merge with Conflicts (for complex merges)
git merge --no-commit <branch>git commit -m "message"Strategy E: Multi-Worktree Selective Merge (combining from multiple sources)
git checkout <branch1> -- <path1>git checkout <branch2> -- <path2>git commit -m "Merge selected files from multiple branches"Execute the selected strategy:
/worktrees compare first)Post-merge summary: Display what was merged:
Cleanup prompt: After successful merge, ask:
git worktree remove <path> for selected worktreesgit worktree prune if needed| Strategy | Use When | Command Pattern |
|---|---|---|
| Selective File | Need complete file(s) from another branch | git checkout <branch> -- <path> |
| Interactive Patch | Need specific changes within a file | git checkout -p <branch> -- <path> |
| Cherry-Pick Selective | Need a commit but not all its changes | git cherry-pick --no-commit + selective staging |
| Manual Merge | Full branch merge with control | git merge --no-commit + selective staging |
| Multi-Source | Combining files from multiple branches | Multiple git checkout <branch> -- <path> |
Merge single file from worktree:
> /worktrees merge src/app.js --from ../project-feature
# Prompts for merge strategy
# Executes: git checkout feature-branch -- src/app.jsInteractive patch selection:
> /worktrees merge src/utils.js --patch
# Lists available worktrees to select from
# Runs: git checkout -p feature-branch -- src/utils.js
# User selects hunks interactively (y/n/s/e)Cherry-pick specific commit:
> /worktrees merge abc1234
# Detects commit hash
# Asks: Apply entire commit or selective?
# If selective: git cherry-pick --no-commit abc1234
# Then guides through unstaging unwanted changesFull guided mode:
> /worktrees merge
# Lists all worktrees
# Asks what to merge (files, commits, or branches)
# Guides through appropriate strategy
# Offers cleanup at endDirectory merge with conflicts:
> /worktrees merge src/components/ --from ../project-refactor
# Strategy D: Manual merge with conflicts
# git merge --no-commit refactor-branch
# Helps resolve any conflicts
# Reviews and commits selected changesWhen using --patch or Strategy B, the user sees prompts for each change hunk:
@@ -10,6 +10,8 @@ function processData(input) {
const result = transform(input);
+ // Added validation
+ if (!isValid(result)) throw new Error('Invalid');
return result;
}
Apply this hunk? [y,n,q,a,d,s,e,?]| Key | Action |
|---|---|
y | Apply this hunk |
n | Skip this hunk |
q | Quit (don't apply this or remaining hunks) |
a | Apply this and all remaining hunks |
d | Don't apply this or remaining hunks in this file |
s | Split into smaller hunks |
e | Manually edit the hunk |
? | Show help |
For Strategy C (cherry-picking with selective staging):
# 1. Apply commit without committing
git cherry-pick --no-commit abc1234
# 2. Check what was staged
git status
# 3. Unstage files you don't want
git reset HEAD -- path/to/unwanted.js
# 4. Discard changes to those files
git checkout -- path/to/unwanted.js
# 5. Commit the remaining changes
git commit -m "Cherry-pick selected changes from abc1234"For Strategy E (merging from multiple worktrees):
# Get files from different branches
git checkout feature-auth -- src/auth/login.js src/auth/session.js
git checkout feature-api -- src/api/endpoints.js
git checkout feature-ui -- src/components/Header.js
# Review all changes
git status
git diff --cached
# Commit combined changes
git commit -m "feat: combine auth, API, and UI improvements from feature branches"> /worktrees merge src/new-feature.js --from ../project-feature
# Gets just the file, not the entire branch> /worktrees merge --patch src/utils.js --from ../project-hotfix
# Select only the specific bug fix hunks, not all changes> /worktrees merge --interactive
# Select specific files from PR-1 worktree
# Select other files from PR-2 worktree
# Combine into single coherent commit# First review what will be merged
> /worktrees compare src/module.js
# Then merge with confidence
> /worktrees merge src/module.js --from ../project-featureWorking directory state: Always ensure your working directory is clean before merging. Uncommitted changes can cause conflicts.
Pre-merge review: Consider using /worktrees compare before merging to understand what changes will be applied.
Conflict resolution: If conflicts occur during merge, the command will help identify and resolve them before committing.
No-commit flag: Most strategies use --no-commit to give you control over the final commit message and what gets included.
Shared repository: All worktrees share the same Git object database, so commits made in any worktree are immediately visible to cherry-pick from any other.
Branch locks: Remember that branches can only be checked out in one worktree at a time. Use branch names for merge operations rather than creating duplicate worktrees.
After merging, consider cleaning up worktrees that are no longer needed:
# List worktrees
git worktree list
# Remove specific worktree (clean state required)
git worktree remove ../project-feature
# Force remove (discards uncommitted changes)
git worktree remove --force ../project-feature
# Clean up stale worktree references
git worktree pruneThe command will prompt you about cleanup after each successful merge to help maintain a tidy workspace.
"Cannot merge: working directory has uncommitted changes"
git stash before merge, git stash pop after"Merge conflict in <file>"
<<<<<<< markers)git add <file>git commit"Commit not found" when cherry-picking
git log <branch> in any worktree to find commits"Cannot checkout: file exists in working tree"
"Branch not found for worktree"
git worktree list to see current worktreesgit worktree prune to clean up stale referencesPre-merge review:
> /worktrees compare src/
> /worktrees merge src/specific-file.jsCreate worktree, merge, cleanup:
> /worktrees create feature-branch
> /worktrees compare src/
> /worktrees merge src/module.js --from ../project-feature-branch
# After merge, cleanup is offered automatically© NeoLabHQ, GPL-3.0. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file
Just SKILL.md in skills/git-worktrees of NeoLabHQ/context-engineering-kit.
Open the folder on GitHubat commit 23e2428
Git Worktrees next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.
| Skill | Stars | Used in | Tokens | Auto-check | Licence | Repo updated |
|---|---|---|---|---|---|---|
| Git Worktrees this skillNeoLabHQ/context-engineering-kit | 1.7k | — | ~10k | Automated safety check: Pass | GPL-3.0 | |
| Build Px4 macOSPX4/PX4-Autopilot | 13k | — | ~1.1k | Automated safety check: Pass | BSD-3-Clause | |
| WorktreeAgentsMesh/AgentsMesh | 2.4k | — | ~553 | Automated safety check: Notes | Custom licence | |
| Git Worktree IsolationjnMetaCode/superpowers-zh | 8.3k | 1 repos | ~982 | Automated safety check: Pass | MIT | |
| Cursor Composer Task DelegateChachamaru127/claude-code-harness | 3.2k | — | ~4.4k | Automated safety check: Notes | MIT | |
| Git Worktree Setupk8zdev/k8z | 155 | — | ~930 | Automated safety check: Pass | None |
PX4/PX4-Autopilot
Build PX4 board firmware on macOS in the px4-dev Docker container, including git worktrees, and stage commit-labeled artifacts without flashing hardware.
AgentsMesh/AgentsMesh
Creates or reuses an isolated AgentsMesh Git worktree from a verified base branch, preserves existing changes, and optionally starts the worktree-scoped development environment.
jnMetaCode/superpowers-zh
Sets up an isolated workspace before feature work or plan execution, preferring native worktree tools and falling back to git worktree, with instructions in Chinese.
Chachamaru127/claude-code-harness
Hands one implementation task to Cursor Composer in an isolated git worktree, then reviews its diff and cherry-picks the result into the main branch.
k8zdev/k8z
Automate git worktree creation and copy private files (not tracked in git) to new workdirs.
michaelshimeles/skills
Start a new task in an isolated Git worktree branched from origin/main so multiple agents can work on the same repo in parallel without conflicts.
NeoLabHQ/context-engineering-kit
A skill your agent uses when you writing commands, hooks, skills for Agent, or prompts for sub agents or any other LLM interaction, including optimizing prompts, improving LLM outputs, or designing…
NeoLabHQ/context-engineering-kit
A skill your agent uses when adding metadata to commits without changing history, tracking review status, test results, code quality annotations, or supplementing commit messages post-hoc - provides…
NeoLabHQ/context-engineering-kit
Design multi-agent architectures for complex tasks. An agent skill from NeoLabHQ/context-engineering-kit.
NeoLabHQ/context-engineering-kit
A skill your agent uses to load open/unresolved PR review comments then aggregate them as tasks in .specs/comments/.md for parallel agents to fix.
NeoLabHQ/context-engineering-kit
Review an existing GitHub pull request and post inline review comments on its diff.
NeoLabHQ/context-engineering-kit
A skill your agent uses when executing implementation plans with independent tasks in the current session or facing 3+ independent issues that can be investigated without shared state or…
Works with
Categories
A skill your agent uses when working on multiple branches simultaneously, context switching without stashing, reviewing PRs while developing, testing in isolation, or comparing implementations…. Git Worktrees is an agent skill from NeoLabHQ/context-engineering-kit. Use when working on multiple branches simultaneously, context switching without stashing, reviewing PRs while developing, testing in isolation, or comparing implementations across branches - provides git worktree commands and workflow patterns for parallel development with multiple working directories.
Git Worktrees fits situations like: working on multiple branches simultaneously; context switching without stashing; reviewing PRs while developing; testing in isolation.
Run `npx skills add NeoLabHQ/context-engineering-kit --skill git-worktrees -a claude-code`. Or copy the skill folder (skills/git-worktrees in NeoLabHQ/context-engineering-kit) into .claude/skills/git-worktrees in your project. Claude Code loads it when a task matches its description.
Run `npx skills add NeoLabHQ/context-engineering-kit --skill git-worktrees -a codex`. Or copy the skill folder (skills/git-worktrees in NeoLabHQ/context-engineering-kit) into .agents/skills/git-worktrees in your project. Codex loads it when a task matches its description.
Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add NeoLabHQ/context-engineering-kit --skill git-worktrees -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/git-worktrees, .gemini/skills/git-worktrees, .github/skills/git-worktrees and .opencode/skills/git-worktrees in your project.
Going by SKILL.md and its folder, Git Worktrees needs the command-line tools its instructions call (git, npm, bun, pnpm and yarn).
SKILL.md contains no URLs. Its commands use git and npm, which can reach the network depending on how they are called. This is read from the text; nothing was executed.
Our automated static check of SKILL.md found no risky patterns, such as piping downloads into a shell, reading credential files or hidden Unicode. It is not a guarantee. Review the folder before installing.
Git Worktrees is published under the GPL-3.0 licence (the repository's licence). It allows redistribution, so the full SKILL.md is shown on this page.
About 10k tokens (SKILL.md is roughly 41k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full.
Skills that share tags, products or a category with Git Worktrees: Build Px4 macOS (PX4/PX4-Autopilot, 13k stars), Worktree (AgentsMesh/AgentsMesh, 2.4k stars), Git Worktree Isolation (jnMetaCode/superpowers-zh, 8.3k stars) and Cursor Composer Task Delegate (Chachamaru127/claude-code-harness, 3.2k stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.
NeoLabHQ (a GitHub organization) maintains it in NeoLabHQ/context-engineering-kit, which has 1,748 GitHub stars. The repository holds 57 skills in this directory. The repository was last updated on August 26, 2026.
Source: NeoLabHQ/context-engineering-kit on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.