Git worktree management utilities for efficient multi-branch workflows.
Add this line to your ~/.zshrc or ~/.bashrc:
source ~/.claude/claude-bash-utils.shThen restart your shell or run:
source ~/.zshrc # or source ~/.bashrcCreates a new git worktree in a sibling trees/<repo-name>/<branch-name> directory.
Behavior:
- If the branch exists: checks it out in the new worktree
- If the branch doesn't exist: creates a new branch and worktree
- Copies files/directories listed in
.worktreeinclude(if present) - Automatically changes into the new worktree directory
Example:
$ wt feature-auth
Creating worktree for branch: feature-auth
Main directory: /Users/you/code/project
Worktree directory: /Users/you/code/trees/project/feature-auth
...
# You're now in the worktree directoryDeletes a worktree, its associated branch, and directory.
Modes:
- With branch name: Deletes the specified worktree
- Without arguments (inside worktree): Deletes the current worktree and returns you to main directory
- Without arguments (outside worktree): Shows usage instructions
Important: Force deletes the branch (-D) and removes the worktree regardless of uncommitted changes.
Examples:
# Delete a specific worktree by branch name
$ wtd feature-auth
Deleting worktree for branch: feature-auth
...
Worktree deleted successfully!
# Delete current worktree (when inside a worktree)
$ cd trees/feature-auth
$ wtd
Deleting current worktree
Branch: feature-auth
...
Worktree deleted successfully!
Returned to main directory: /Users/you/projectCreate a .worktreeinclude file in your repository root to automatically copy files/directories into new worktrees. This is useful for:
node_modules(avoid reinstalling dependencies).envfiles (share local configuration)- Build artifacts or caches
Example .worktreeinclude:
node_modules
.env
.env.local
dist
.cache
When you run wt new-branch, these files/directories will be copied from the main worktree to the new worktree.
# In your main repository
$ git status
On branch main
# Create a worktree for a new feature
$ wt feature-login
# Now in ../trees/project/feature-login with feature-login branch
# Do your work
$ git add .
$ git commit -m "Add login feature"
# Go back to main directory to create another worktree
$ cd /path/to/project # or use: cd ../../project
$ wt bugfix-header
# Work on the bugfix
$ git add .
$ git commit -m "Fix header bug"
# Delete the feature worktree when done
$ wtd feature-login
# Or navigate into it and run: wtd
# Clean up the bugfix worktree
$ cd ../trees/project/bugfix-header
$ wtd
# Returns you to main directoryGit worktrees allow you to have multiple branches checked out simultaneously in different directories, enabling:
- Quick context switching without stashing or committing incomplete work
- Parallel development on multiple features/bugs
- Easy testing by running different branches side-by-side
- Clean separation of different workstreams
Instead of:
git stash
git checkout other-branch
# do work
git checkout original-branch
git stash popYou can simply:
wt other-branch
# do work
wtd