Worktree Manager (wtm) is a CLI tool that makes Git worktree workflows easier and more pleasant, especially during code reviews.
It helps you create, switch, and remove worktrees to make code review easier.
It can also install dependencies and run jobs.
wtm <option> <branch-or-path>
Branch names do not need origin prefixed. Local branches are automatically created if not present.
Available options are
create: creates a new worktree from a branch (specifyingoriginis not necessary)remove: removes an existing worktree (autocompletes fromworktree-dir)list: lists your available worktreesswitch: brings up a fzf prompt to select a worktree and changes cwd to that worktree.--help: prints a help menu
Important
You must install the appropriate shell function wtm for the switch command to work properly.
In order to use the switch command you'll need to add the wtm function to your shell like this:
source $(brew --prefix)/share/wtm/wtm.bash
source $(brew --prefix)/share/wtm/wtm.zsh
ln -s (brew --prefix)/share/wtm/wtm.fish ~/.config/fish/functions/wtm.fish
or
source (brew --prefix)/share/wtm/wtm.fish
Configuration is handled by a file either at
~/.config/worktree-manager/config.json or ~/.worktree-manager
Options are listed here.
worktree-diris where your worktrees will be createdmain-worktree-diris the root of your project, called the "main worktree"
Note that both of these should be absolute paths.
{
"worktree-dir": "<absolute path to a directory to put worktrees>",
"main-worktree-dir": "<absolute path to your project file>",
"jobs": []
}Jobs are run after you create a worktree, and are defined in your config file.
There are 3 kinds of valid jobs
Strings are a valid job. This is a command that will be run in main-worktree-dir.
There are two kinds of object jobs. Both have a key command, which is the
command to run, but you can additionally specify dir to run that command in a
directory relative to the root, or you can specify dirs to run the same
command in different directories (also all relative to the root).
The following are all valid jobs
"npm install"
{
"command": "npm install",
"dir": "client"
}{
"command": "npm install",
"dirs": ["client", "server", "."]
}brew tap bolivier/worktree-manager
brew install worktree-managerInstall babashka
Put <workspace-root>/bin/wtm on your path. There's a task you can run with bb install that will stick it in ~/bin.
Install autocomplete so you don't have to type branch names or worktree paths to remove.
Symlink the autocomplete file <workspace-root>/resources/autocomplete/wtm.fish to ~/.config/fish/completions/wtm.fish.
Add a line in your .zshrc to source the file <workspace-root>/resources/autocomplete/wtm-completion.zsh
Add a line in your .bashrc to source the file <workspace-root>/resources/autocomplete/wtm-completion.bash
