Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

git-worktree-utils

A CLI tool for managing Git worktrees with native hooks support and enhanced functionality.

Installation

# Compile from sources
deno task compile

# The binaries will be created: ./git-worktree-utils and ./git-hooks

Quick Usage

Initialize a project

# 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

Manage worktrees

# 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

Manage hooks

# 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-update

Native Hooks System

The tool uses Git's native hooks system located in <git-dir>/hooks/. Hooks are triggered automatically during worktree operations:

Worktree Hooks

  • pre-add-worktree / post-add-worktree: Before/after creating a worktree
  • pre-remove-worktree / post-remove-worktree: Before/after removing a worktree
  • pre-lock-worktree / post-lock-worktree: Before/after locking a worktree
  • pre-move-worktree / post-move-worktree: Before/after moving a worktree
  • pre-prune-worktree / post-prune-worktree: Before/after pruning worktrees
  • pre-unlock-worktree / post-unlock-worktree: Before/after unlocking a worktree
  • pre-repair-worktree / post-repair-worktree: Before/after repairing a worktree

Environment Variables

Hooks receive these environment variables:

  • GIT_WT_ROOT: Path to the git repository root
  • GIT_WT_MAIN_PATH: Path to the main worktree
  • GIT_WT_WORKTREE_PATH: Path to the current worktree

Example Hook Script

#!/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
fi

Complete Documentation

See SPECIFICATIONS.md for complete documentation.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages