@k11r/kwt
v0.1.0
Published
k11r Worktree Tool - A TypeScript wrapper around git worktrees
Downloads
43
Maintainers
Readme
KWT - k11r Worktree Tool
A modern TypeScript wrapper around git worktrees with GitLab and GitHub integration and intelligent configuration management.
Features
- 🚀 Easy worktree management - Create, remove, and list git worktrees with simple commands
- 🔧 Flexible prefix configuration - Support for none, manual, or auto-detected prefixes
- 🦊 GitLab integration - Create worktrees directly from merge requests using
glab - 🐙 GitHub integration - Create worktrees directly from pull requests using
gh - ⚙️ Post-creation commands - Run custom commands after worktree creation
- 📁 Smart configuration - Local and global configuration with intelligent merging
- 🎯 TypeScript first - Fully typed with strict TypeScript configuration
- 🛠️ Modern tooling - Built with latest Node.js, ESBuild, and comprehensive linting
Installation
Global Installation
npm install -g kwtLocal Development
git clone <repository-url>
cd worktree-tool
npm install
npm run build
npm link # For global access during developmentQuick Start
Initialize configuration in your git repository:
kwt config --initCreate a new worktree:
kwt new feature-branchCreate worktree from GitLab MR:
kwt mr 123Create worktree from GitHub PR:
kwt pr 123List all worktrees:
kwt listRemove a worktree:
kwt rm feature-branch
Commands
kwt new <name>
Create a new worktree with the specified name.
Options:
-b, --branch <name>- Custom branch name (defaults to worktree name)--no-push- Don't push the new branch to origin--dry-run- Show what would be done without executing
Examples:
kwt new feature-auth
kwt new bugfix-login --branch fix/login-issue
kwt new experiment --no-pushkwt mr <number>
Create a worktree from a GitLab merge request.
Options:
--checkout- Checkout existing worktree if it exists--dry-run- Show what would be done without executing
Examples:
kwt mr 123
kwt mr 456 --checkoutRequirements:
glabCLI tool must be installed and configured- Must be run in a GitLab project repository
kwt pr <number>
Create a worktree from a GitHub pull request.
Options:
--checkout- Checkout existing worktree if it exists--dry-run- Show what would be done without executing
Examples:
kwt pr 123
kwt pr 456 --checkoutRequirements:
ghCLI tool must be installed and configured- Must be run in a GitHub project repository
kwt rm <name>
Remove a worktree and optionally its branch.
Options:
-f, --force- Force removal without confirmation--dry-run- Show what would be done without executing
Examples:
kwt rm feature-auth
kwt rm old-feature --forcekwt config
Manage configuration settings.
Options:
--init- Initialize local configuration--global- Use global configuration--set <key=value>- Set a configuration value--get <key>- Get a configuration value--list- List all configuration values
Examples:
kwt config --init
kwt config --set prefixType=detect
kwt config --set worktreeDir=../my-worktrees
kwt config --get prefixType
kwt config --listkwt list
List all existing worktrees.
Aliases: ls
Configuration
KWT uses a hierarchical configuration system with global and local settings.
Configuration Files
- Global:
~/.kwt- User-wide settings - Local:
.kwtin your repository - Project-specific settings
Local settings override global settings.
Configuration Options
prefixType
Controls how worktree names are prefixed:
"none"- No prefix (default)"manual"- Use manually specified prefix"detect"- Auto-detect from git remote
manualPrefix
Custom prefix when prefixType is "manual".
Examples:
{
"prefixType": "manual",
"manualPrefix": "myproject-"
}worktreeDir
Directory where worktrees are created (relative to repository root).
Default: "../worktrees"
postCommands
Array of commands to run after worktree creation.
Example:
{
"postCommands": [
{
"label": "Install dependencies",
"commands": ["npm install"]
},
{
"label": "Setup environment",
"commands": ["cp .env.example .env", "npm run setup"]
}
]
}Example Configuration
{
"prefixType": "detect",
"worktreeDir": "../worktrees",
"postCommands": [
{
"label": "Install dependencies",
"commands": ["npm install"]
},
{
"label": "Run initial setup",
"commands": ["npm run setup"]
}
]
}Prefix Detection
When prefixType is set to "detect", KWT automatically generates prefixes from your git remote:
[email protected]:user/my-repo.git→my-repo-https://gitlab.com/user/awesome-project.git→awesome-project-
GitLab Integration
KWT integrates with GitLab through the glab CLI tool:
- Install glab: Follow glab installation guide
- Authenticate:
glab auth login - Use MR command:
kwt mr <merge-request-number>
The tool will:
- Verify the MR exists
- Fetch the source branch
- Create a worktree with an appropriate name
- Run post-creation commands
GitHub Integration
KWT integrates with GitHub through the gh CLI tool:
- Install gh: Follow gh installation guide
- Authenticate:
gh auth login - Use PR command:
kwt pr <pull-request-number>
The tool will:
- Verify the PR exists
- Fetch the head branch
- Create a worktree with an appropriate name
- Run post-creation commands
Development
Prerequisites
- Node.js 22.17.0+ (see
.nvmrc) - npm or yarn
Setup
git clone <repository-url>
cd worktree-tool
npm installScripts
npm run build- Build the projectnpm run dev- Build in watch modenpm run test- Run testsnpm run lint- Lint codenpm run format- Format codenpm run typecheck- Type check
Architecture
- TypeScript with strict configuration
- ESM modules for modern Node.js
- Commander.js for CLI framework
- Zod for configuration validation
- Execa for process execution
- Cosmiconfig for configuration management
License
MIT License - see LICENSE file for details.
Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Run linting and tests
- Submit a pull request
Troubleshooting
Common Issues
"Not in a git repository"
- Ensure you're running KWT from within a git repository
"glab CLI not available"
- Install and configure the GitLab CLI tool for MR functionality
"Worktree already exists"
- Use
kwt listto see existing worktrees - Use
kwt rm <name>to remove conflicting worktrees
Permission denied on CLI
- Ensure the binary is executable:
chmod +x dist/cli.js
Debug Mode
Use the --verbose (or -d) flag for detailed logging:
kwt --verbose new my-feature
kwt -d new my-feature