Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 

Repository files navigation

git-worktree-helper

Three tiny git aliases that make git worktrees easy to use — no more remembering the full git worktree add/list/remove syntax.

Worktrees are created in a .worktrees/ folder at the root of your repository, and the folder is automatically added to .gitignore. The aliases live in your global git config, so they work in every repo, on Windows, macOS, and Linux, and in any shell (bash, zsh, PowerShell, cmd) — Git ships its own sh on Windows, so the same config runs everywhere.

The aliases

Command What it does
git wt List all worktrees. Ensures .worktrees/ is in .gitignore.
git wtn <branch> Create a new branch and a worktree for it at <repo-root>/.worktrees/<branch>, then print the path.
git wtr <branch> Remove the worktree at <repo-root>/.worktrees/<branch>, then print the path.
$ git wtn feature-login
Preparing worktree (new branch 'feature-login')
Created worktree for branch feature-login at /path/to/repo/.worktrees/feature-login

$ git wt
/path/to/repo                        a1b2c3d [main]
/path/to/repo/.worktrees/feature-login  e4f5g6h [feature-login]

$ git wtr feature-login
Removed worktree for branch feature-login at /path/to/repo/.worktrees/feature-login

Branch names with slashes (e.g. feature/login) create nested folders under .worktrees/ — that works, just pass the same name to git wtr.

Install

Option A — AI agent (one-liner prompt)

Paste this prompt into an AI coding agent (GitHub Copilot CLI, Claude Code, Cursor, etc.):

Install the git worktree aliases from https://github.com/dryotta/git-worktree-helper.
Read that repo's README and run the three `git config --global` install commands from
the "Manual install" section as-is (they are shell-agnostic). Then verify the install
by running: git config --get-regexp "^alias\.wt"

Option B — Manual install

Run these three commands. They are wrapped in single quotes so they work identically in bash, zsh, and PowerShell — copy and paste them as-is.

git config --global alias.wt '!f() { root=$(git rev-parse --show-toplevel); grep -qxF .worktrees/ "$root/.gitignore" 2>/dev/null || echo .worktrees/ >> "$root/.gitignore"; git worktree list; }; f'

git config --global alias.wtn '!f() { root=$(git rev-parse --show-toplevel); grep -qxF .worktrees/ "$root/.gitignore" 2>/dev/null || echo .worktrees/ >> "$root/.gitignore"; path="$root/.worktrees/$1"; git worktree add -b "$1" "$path" && echo "Created worktree for branch $1 at $path"; }; f'

git config --global alias.wtr '!f() { root=$(git rev-parse --show-toplevel); path="$root/.worktrees/$1"; git worktree remove "$path" && echo "Removed worktree for branch $1 at $path"; }; f'

Verify:

git config --get-regexp "^alias\.wt"

Option C — Copy into your gitconfig

Copy the [alias] block from aliases.gitconfig into your global git config file (~/.gitconfig).

Usage

git wt                  # list all worktrees
git wtn my-feature      # new branch + worktree at ./.worktrees/my-feature
git wtr my-feature      # remove that worktree

Uninstall

git config --global --unset alias.wt
git config --global --unset alias.wtn
git config --global --unset alias.wtr

How it works

  • Aliases beginning with ! run as shell commands. The f() { ... }; f wrapper defines a one-shot function so the alias can take positional arguments ($1).
  • git rev-parse --show-toplevel finds the repository root, so the commands work from any subdirectory.
  • The .gitignore guard uses grep -qxF (quiet, whole-line, fixed-string) and only appends .worktrees/ when it is missing — it never adds a duplicate.
  • Status messages use &&, so they only print when the underlying git worktree command succeeds.

Requirements

  • Git 2.5+ (when git worktree was introduced; 2.17+ recommended for worktree remove).
  • On Windows, use Git for Windows (bundles the sh, grep, and echo these aliases rely on).

License

MIT

About

Three simple, cross-platform git aliases (wt/wtn/wtr) for managing git worktrees under .worktrees/

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors