cli tool: worktrunk
Git worktrees are amazing in concept. But maintaining them is a chore.
The worktrunk cli tool makes it easy to manage multiple worktrees. It creates
worktrees from the main branch, and automatically copies ignored files from
the main repository to the new worktree, think .env file, node_modules, or
dist folders.
Install
brew install worktrunkwt config shell install
This will install the wt cli tool and set up shell completions for your shell.
Prepare your repository
Ideally, we clone a bare repository and create a main worktree from it:
git clone --bare <repo-url> <repo-name>cd <repo-name>wt switch -c main # creates a new worktree from the main branch, cds into it.
Configure ignored files
Add the following config file:
# .config/wt.toml[post-start]copy = "wt step copy-ignored"
This will copy the ignored files in the background after creating a new worktree.
If you want to control which files are copied, you can create a
.worktreeinclude file:
# .worktreeinclude# List of files and folders to copy to new worktrees.envnode_modules.vscode
Important commands
# create a new worktree from the main branch and cd into itwt switch# interactively select a worktree to switch towt switch# create a new worktree with a specific branch namewt switch -c branch-name# list all worktreeswt list# remove a worktreewt remove branch-name
If you want to know more about the features and configuration options, check out the documentation.