Skip to main content

worktree-aid

PyPi AUR

This is a command line tool to easily add, remove, and change directories for git worktrees. Prompts user with list of worktrees using fuzzy finder.

After following the instructions in the Installation and Setup sections below, an wt shell command/alias is available to use to manage git worktrees. There are 3 commonly used commands:

  • wt add (or wt a) to add a new worktree + branch and automatically cd to it. If you don't specify a worktree name, a new unique name will be automatically created for you.

  • wt cd (or wt c) to change directory to a specified worktree. You can use / as a shortcut to the toplevel repository directory. If you don't specify a worktree name, then a fuzzy finder will prompt you with a list of worktrees to select from and be cd'd to.

  • wt rm (or wt r) to remove a worktree + branch. If you don't specify a worktree name, then a fuzzy finder will prompt you with a list of worktrees to select from. The current worktree is first in the list and is the default selection to remove. If you remove the current worktree then you will be automatically cd'd to the toplevel repository directory.

There are some other options and commands available, as described in the next section. Type wt to see an overall help/usage summary, or wt <command> -h to see specific help/usage for any individual command.

The project homepage and latest documentation is at https://github.com/bulletmark/worktree-aid.

Usage

Type wt or wt -h to view the usage summary:

usage: wt [-P PATH] [-R] [-r] [-U] [-u] [-F FUZZY] [-V] [-h]
                       {add,a,rm,r,cd,c,fetch,f,ls,l,init} ...

Command line tool to easily add, remove, and change directories for git
worktrees. Prompts user with list of worktrees using fuzzy finder.

options:
  -P, --path PATH       directory path template for newly added worktrees,
                        default="../worktrees/{repo}/{worktree}". Can use
                        {worktree}, {repo}, {user}, and {home} placeholders.
                        Must contain {worktree} at least.
  -R, --relative        display worktree paths relative instead of absolute
  -r                    toggle -R/--relative option for one-off command only
  -U, --no-user         do not substitute "~" for user home directory
  -u                    toggle -U/--no-user option for one-off command only
  -F, --fuzzy FUZZY     fuzzy finder program, default="fzf"
  -V, --version         show program version and exit
  -h, --help            show help message and exit

Commands:
  {add,a,rm,r,cd,c,fetch,f,ls,l,init}
    add (a)             Add new worktree + branch.
    rm (r)              Remove worktree + branch.
    cd (c)              Change worktree directory.
    fetch (f)           Fetch changes from another worktree.
    ls (l)              List worktrees.
    init                Output shell initialization code.

Type wt <command> -h to see specific help/usage for any individual command:

Command add

usage: wt add [-h] [-d] [-c] [worktree ...]

Add new worktree + branch.

positional arguments:
  worktree      new worktree + branch to add. A name is automatically created
                if not specified.

options:
  -h, --help    show help message and exit
  -d, --detach  add detached worktree only, i.e. without adding a new branch
  -c, --no-cd   do not change directory to new worktree after adding it

aliases: a

Command rm

usage: wt rm [-h] [-k] [-f] [-a] [worktree ...]

Remove worktree + branch.

positional arguments:
  worktree           worktree + branch name to remove. "." is a shortcut to
                     the current worktree. If not specified then fuzzy finder
                     will prompt with a list of worktrees, with the current
                     worktree as the default selection.

options:
  -h, --help         show help message and exit
  -k, --keep-branch  remove worktree but keep branch
  -f, --force        force removal of worktree + branch even if untracked or
                     unmerged changes exist.
  -a, --all          remove all worktrees

aliases: r

Command cd

usage: wt cd [-h] [worktree]

Change worktree directory.

positional arguments:
  worktree    Worktree name to change directory to. "/" is a shortcut to the
              toplevel repository. If not specified then fuzzy finder will
              prompt with a list of worktrees.

options:
  -h, --help  show help message and exit

aliases: c

Command fetch

usage: wt fetch [-h] [-q] [worktree]

Fetch changes from another worktree.

positional arguments:
  worktree     Worktree name to copy from. "/" is a shortcut to the toplevel
               repository. If not specified then fuzzy finder will prompt with
               a list of worktrees.

options:
  -h, --help   show help message and exit
  -q, --quiet  suppress output of copied files

aliases: f

Command ls

usage: wt ls [-h]

List worktrees.

options:
  -h, --help  show help message and exit

aliases: l

Command init

usage: wt init [-h] [command]

Output shell initialization code. Must be invoked using `source <(worktree-
aid)` in your shell `~/.bashrc` or `~/.zshrc` initialization file to create
the shell alias/function by which you invoke this program.

positional arguments:
  command     alternative command name, and optional default arguments,
              default="wt"

options:
  -h, --help  show help message and exit

Installation or Upgrade

Python 3.10 or later is required. Install using uv tool:

$ uv tool install worktree-aid

# To upgrade:
$ uv tool upgrade worktree-aid

# To uninstall:
$ uv tool uninstall worktree-aid

Or, on Arch Linux:

$ yay -S worktree-aid  # or your preferred AUR helper

Git is required to execute all commands. You also need to install a fuzzy finder program such as fzf which is the default used by worktree-aid. See fuzzy finder installation instructions for possible alternatives.

Setup

A user who wants to use worktree-aid must add the following line to their ~/.bashrc (bash user) or ~/.zshrc (zsh user). Ensure it is added after where your PATH is set up so that the command worktree-aid can be found. This creates the wt wrapper command in your interactive shell session as a tiny function.

source <(worktree-aid init)

Then log out and back in again to be able to use the new wt function in your shell.

Alternative Command Name

You can use an alternative command name instead of the default wt if you prefer. To do this, simply append your desired command name as the first argument to the worktree-aid init option in your shell initialization code.

E.g, to use the command name wx rather than the default wt, use the following in your ~/.bashrc or ~/.zshrc file:

source <(worktree-aid init wx)

Then log out/in, and then use wx command instead of the default wt.

Default Options

You can also set default worktree-aid options by appending options in the shell initialization code, e.g:

source <(worktree-aid init "wt -R")

The above sets -R (for relative display of worktree directories) as default for your wt command.

The following options are sensible candidates to set as default options: -P/--path, -R/--relative, -U/--no-user, -F/--fuzzy.

Directory Path Template for new Worktree Creation

The -P/--path option allows you to specify the directory path template for newly added worktrees. It is set to a default as below but you can change this to any directory you like. It can be absolute or relative where relative paths are relative to base toplevel repository directory.

  • Default base directory is -P ../worktrees/{repo}/{worktree}.
  • E.g. can use -P ../worktrees/{repo}/{worktree}/{repo} which is same as Zed editor creates by default.
  • E.g. can use -P ../{repo}.worktrees/{worktree} which is same as VS Code editor creates by default.
  • E.g. can use -P ~/worktrees/{repo}/{worktree} to create all worktrees within a subdirectory of your home directory.

The following placeholders can be used in the definition of the directory template:

  • {worktree}: Substituted with the name of the worktree/branch.
  • {repo}: Substituted with the base name of the repository.
  • {user}: Substituted with the name of the user.
  • {home}: Substituted with the home directory of the user (also can use ~ at start of a path).

Your path definition must at least contain the {worktree} placeholder.

Most likely if you want to set a custom path then you will set -P as a default option.

Note that the --P/--path setting is only relevant when adding a new worktree using the add command. All other commands query your existing worktrees so will work regardless of how or where the worktrees were created.

Display as Relative Worktree Directories

The git worktree list command displays absolute directory paths, and worktree-aid does also by default, but many users prefer them displayed as shorter relative paths which git worktree does not provide. You can enable it in worktree-aid however, by adding the -R/--relative option, e.g:

$ wt l
../worktrees/worktree-aid/development 9796714 [development]
../worktrees/worktree-aid/milestone1  bc921b8 [milestone1]
../worktrees/worktree-aid/test        e6d965a [test]
                                      f76b8e0 [main]

Most likely you will want to set -R as a default option. Note you can use the -r option on a one-off command to temporarily toggle whatever your default -R/--relative option is set as.

Fuzzy Finder Integration

fzf is the default fuzzy finder used by worktree-aid, but you can use any of the popular other command line fuzzy search finders such as sk, tv, or fzy.

E.g. to use sk, put this in your ~/.bashrc or ~/.zshrc file:

source <(worktree-aid init "wt -F sk")

You can also get fancy and add preview options etc to your fuzzy finder command line. Most likely you will want to set -F as a default option.

License

GPL-3.0-or-later.

Metadata

Release files for worktree-aid 1.9

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for worktree-aid 1.9
File Size Uploaded
worktree_aid-1.9.tar.gz 12.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for worktree-aid 1.9
File Interpreter ABI Platform
worktree_aid-1.9-py3-none-any.whl Python 3 none any Details

Total release size: 23.2 kB

Release files / worktree_aid-1.9.tar.gz

Download URL worktree_aid-1.9.tar.gz
Size 12.0 kB
Tags Source
SHA-256 checksum
How to use checksums
dfb436cb716306f3702afa23596a9d00ab381769ac423a912c13a54ca25bf09a
BLAKE2b-256 checksum
How to use checksums
ab3a751ffe1bdd9853d62459a889b360fb3ae317281a914b77ae751a8641f610
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.3 {"installer":{"name":"uv","version":"0.12.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Arch Linux","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / worktree_aid-1.9-py3-none-any.whl

Download URL worktree_aid-1.9-py3-none-any.whl
Size 11.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1e039c85287d02d51dfcc29832773cd7e3effd3fe4e0b263074290d80c038831
BLAKE2b-256 checksum
How to use checksums
1d715a7ee648c18f10578a8da2d9ee2140550713c67e4fd996fbadb1165b277b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.3 {"installer":{"name":"uv","version":"0.12.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Arch Linux","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release history Release notifications | RSS feed

1.21

2 release files

1.20

2 release files

1.19

2 release files

1.18

2 release files

1.17

2 release files

1.16

2 release files

1.15

2 release files

1.14

2 release files

1.13

2 release files

1.12

2 release files

1.11

2 release files

1.10

2 release files

This release

1.9 This release

2 release files

1.8

2 release files

1.7

2 release files

1.6

2 release files

1.5

2 release files

1.4

2 release files

1.3

2 release files

1.2

2 release files

1.1

2 release files

1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page