wapa5pow/workhere

★ 0Forks 0JavaScriptGitHub ↗Compare

README

workhere

A simple git worktree management tool that creates worktrees in the .git/worktree directory of your current Git repository.

Installation

npm install -g workhere

Or run directly with npx:

npx workhere@latest

Usage

Commands

Create a worktree

workhere create [branch-name]
workhere add [branch-name]  # Alias for create

If no branch name is specified, it will automatically create one with a random name like alice-smith-a1b2 or bob-jones-c3d4.

List worktrees

workhere list
workhere ls  # Short alias for list

Shows all worktrees managed by workhere in the current repository.

Delete a specific worktree

workhere delete <branch-name>
workhere remove <branch-name>  # Alias for delete
workhere rm <branch-name>      # Short alias for delete

Removes the specified worktree and its associated branch.

Reset (delete all worktrees)

workhere reset

Removes all worktrees in the .git/worktree directory.

Options

Folder Name Prefix (create/add command)

To automatically add the current folder name as a prefix to the worktree folder name (branch name stays unchanged):

workhere create -p [branch-name]
workhere add --prefix [branch-name]

Examples (if current folder is "workhere"):

  • workhere add -p feature → folder: workhere-feature, branch: feature
  • workhere add -p → folder: workhere-alice-smith-a1b2, branch: alice-smith-a1b2 (auto-generated)
  • workhere add feature → folder: feature, branch: feature (no prefix)

Running Scripts (create/add command)

To execute a script after creating the worktree:

workhere create -s "npm install && npm run dev" feature-branch
workhere add --script "pnpm install" feature-branch

This will:

  1. Create a worktree named feature-branch
  2. Change to the created worktree directory
  3. Execute the specified script (in this example: npm install && npm run dev)

Base Branch (create/add command)

By default, a new worktree is derived from the current HEAD. To derive it from a specific branch or commit instead:

workhere add --base main feature-branch
workhere add -b origin/develop feature-branch

This creates feature-branch based on the specified ref (main in the first example) regardless of the currently checked-out branch.

Force Deletion

To force delete worktrees even if they have uncommitted changes:

workhere delete -f <branch-name>
workhere reset -f

Features

  • Creates worktrees in the .git/worktree directory of the current repository
  • Supports post-creation script execution (-s option)
  • Checks for existing worktree conflicts
  • Verifies if the current directory is a Git repository
  • Enforces execution from the repository root

Examples

Create a new feature branch

workhere create feature/new-feature
workhere add feature/new-feature  # Using alias

Create worktree with folder prefix

workhere add -p feature
# Creates folder: yourproject-feature, branch: feature (if current folder is "yourproject")

Create worktree from a specific base branch

workhere add --base main feature/new-feature
# Creates feature/new-feature based on main, not the current branch

Install dependencies after creating worktree

workhere create -s "pnpm install" bugfix/issue-123

Start development server with folder prefix

workhere add -p -s "npm install && npm run dev" develop
# Creates folder: yourproject-develop, branch: develop, and runs the script

List all worktrees

workhere list

Delete a specific worktree

workhere delete feature/old-feature

Remove all worktrees at once

workhere reset

Force delete worktrees with uncommitted changes

workhere reset --force

Requirements

  • Node.js >= 14.0.0
  • Git

License

MIT

Contributing

Please report bugs and feature requests to GitHub Issues.

Contributors

wapa5pow

Issues