gwm
Git Worktree Manager (gwm)
Manage git worktrees using the gwm.sh script located at skills/gwm/scripts/gwm.sh in the agent-resources repo.
Arguments
The user invokes this skill as /gwm <command> [args], or by saying something like "create git worktree for KKEP-1234". Parse the command and arguments from the user's input. If the user says "create worktree" or similar without specifying a command, treat it as add.
Supported commands:
add <branch-name> [sparse-path]— Create a new worktree (optionally with sparse checkout)list— List all worktreesremove <branch-name>— Remove a worktree and optionally delete the branchstatus <branch-name>— Show dirty state, ahead/behind for a worktreeprune— Clean up stale worktree referenceshelp— Show available commands
Flags:
--plain— Human-readable output (always use this when presenting results)--no-restore— Skip dotnet restore and file copying after creating a worktree
Configuration
The script uses two directory paths, configurable via environment variables:
GWM_SRC_DIR— The main git repository (default:/d/kkep/projects/kk.erhvervsportal)GWM_WORKTREE_DIR— Where worktrees are created (default:/d/worktrees/kkep)
Branch naming convention
Before running the add command, validate the branch name against the expected pattern KKEP-XYZQ where XYZQ is a four-digit number (e.g. KKEP-1234, KKEP-5678).
- If the branch name does not match this pattern, warn the user that the name deviates from the convention and ask for confirmation before proceeding.
- If the user confirms, proceed with the provided name.
- This validation only applies to the
addcommand.
Instructions
-
Locate the script
- The script is at:
skills/gwm/scripts/gwm.sh(relative to the agent-resources repo root) - It must be run from within the source git repository configured in the script (
SRC_DIR)
- The script is at:
-
Run the command
- Execute:
bash skills/gwm/scripts/gwm.sh <command> [args] - The script outputs JSON by default. Add
--plainfor human-readable output - Always use
--plainwhen presenting results to the user
- Execute:
-
Handle the output
- On success (
status: ok): present the message and relevant data to the user - On error (
status: error): show the error message and suggest corrective action
- On success (
-
After creating a worktree (successful
addcommand)- Use
cdto change into the worktree folder (the path reported in the output) - This ensures subsequent commands run in the context of the new worktree
- Use
-
Examples
- Create a worktree:
bash skills/gwm/scripts/gwm.sh add KKEP-1234 --plain - Create with sparse checkout:
bash skills/gwm/scripts/gwm.sh add KKEP-1234 src/MyProject --plain - Create without restore:
bash skills/gwm/scripts/gwm.sh add KKEP-1234 --no-restore --plain - List worktrees:
bash skills/gwm/scripts/gwm.sh list --plain - Check status:
bash skills/gwm/scripts/gwm.sh status KKEP-1234 --plain - Remove a worktree:
bash skills/gwm/scripts/gwm.sh remove KKEP-1234 --plain - Clean up stale references:
bash skills/gwm/scripts/gwm.sh prune --plain
- Create a worktree:
-
If no command is provided, run
bash skills/gwm/scripts/gwm.sh help --plainand show the available commands.
Troubleshooting
| Error | Cause | Fix |
|---|---|---|
| "Branch already exists locally" | Branch was previously created | Use gwm status <branch> to inspect, or gwm remove <branch> first |
| "Incomplete worktree found" | Previous creation failed partway | Run gwm remove <branch> to clean up, then retry |
| "Sparse path not found" | The path doesn't exist in the repo | Check the path with git ls-tree --name-only HEAD |
| "SRC_DIR does not exist" | Env not configured for this machine | Set GWM_SRC_DIR environment variable |
| "dotnet restore failed" | Build dependencies issue | Use --no-restore to skip, then restore manually |
More from carsten-j/agent-resources
update-claude-md
Update the project's CLAUDE.md with meta learnings, conventions, gotchas, and significant codebase changes. Use when the user asks to update CLAUDE.md, capture learnings, document project conventions, or reflect recent work in the project guide.
11refactor-pass
Perform a refactor pass focused on simplicity after recent changes. Use when the user asks for a refactor/cleanup pass, simplification, or dead-code removal and expects build to verify behavior.
11pr-review
Review the current Pull Request that has been checked out locally with structured feedback on code quality, issues, testing, and suggestions. Use when you need a comprehensive code review of a PR branch.
8history
Display Claude conversation history in an easy-to-scan format showing recent sessions with dates, projects, and topics. Use when you want to review past conversations or resume a previous session.
1teach
Learning mode - guides the user to complete tasks themselves through Socratic teaching rather than doing it for them. Use when the user wants to learn how to do something instead of having it done for them.
1catchup
Catch up on branch changes by reviewing all changes between current branch and master/main, analyzing key files, and providing a comprehensive summary. Use when you need to understand what changed in a feature branch.
1