A CLI tool for managing Git worktrees with native hooks support and enhanced functionality.
# Compile from sources
deno task compile
# The binaries will be created: ./git-worktree-utils and ./git-hooks# Clone an existing repo
git-worktree-utils add main
# Or initialize a new repo
git init my-project
cd my-project
git-worktree-utils add main# Create a new worktree
git-worktree-utils add feature/new-feature
# Create and open in Wezterm
git-worktree-utils add feature/new-feature --open
# List worktrees
git-worktree-utils list
# Open existing worktree
git-worktree-utils open ../feature-work
# Remove a worktree
git-worktree-utils remove feature/new-feature# List all hooks
git-hooks list
# Enable a hook from sample
git-hooks enable post-update
# Disable a hook
git-hooks disable post-update
# Execute a hook manually
git-hooks execute post-updateThe tool uses Git's native hooks system located in <git-dir>/hooks/. Hooks are
triggered automatically during worktree operations:
pre-add-worktree/post-add-worktree: Before/after creating a worktreepre-remove-worktree/post-remove-worktree: Before/after removing a worktreepre-lock-worktree/post-lock-worktree: Before/after locking a worktreepre-move-worktree/post-move-worktree: Before/after moving a worktreepre-prune-worktree/post-prune-worktree: Before/after pruning worktreespre-unlock-worktree/post-unlock-worktree: Before/after unlocking a worktreepre-repair-worktree/post-repair-worktree: Before/after repairing a worktree
Hooks receive these environment variables:
GIT_WT_ROOT: Path to the git repository rootGIT_WT_MAIN_PATH: Path to the main worktreeGIT_WT_WORKTREE_PATH: Path to the current worktree
#!/bin/bash
# .git/hooks/post-add-worktree
echo "Worktree added at: $GIT_WT_WORKTREE_PATH"
echo "Main worktree: $GIT_WT_MAIN_PATH"
echo "Repository root: $GIT_WT_ROOT"
# Install dependencies if package.json exists
if [ -f "$GIT_WT_WORKTREE_PATH/package.json" ]; then
cd "$GIT_WT_WORKTREE_PATH"
npm install
fiSee SPECIFICATIONS.md for complete documentation.