Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Changelog

## [1.4.0] - 2026-02-25

### Added
- Shell aliases (`aliases/git-wt.sh`) — `wtcd`, `wto`, `wtn`, `wtls`, `wtla`, `wtrm`, `wtopen`, `wtclean`, `wtpath`
- `wtn` creates a worktree and `cd`s into it in one step
- `wtcd <name>` jumps into a worktree, `wto` jumps to the origin repo
- Tab completion for aliases (bash + zsh)

## [1.3.0] - 2026-02-25

### Added
Expand Down
1 change: 1 addition & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Wraps `git worktree` into an ergonomic CLI: `git wt <command>`.

```
bin/git-wt — main executable (bash script)
aliases/git-wt.sh — optional shell aliases (wtcd, wto, wtn, etc.)
completions/
git-wt.bash — bash completions
_git-wt — zsh completions
Expand Down
29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,35 @@ git wt open auth-refactor
git wt rm auth-refactor
```

### Shell Aliases

Install the optional aliases for shorter commands:

```bash
curl -fsSL https://raw.githubusercontent.com/kuderr/git-wt/main/aliases/install.sh | bash
```

Or source manually:

```bash
# Add to ~/.bashrc or ~/.zshrc
source /path/to/git-wt/aliases/git-wt.sh
```

| Alias | Equivalent | Description |
|-------|-----------|-------------|
| `wtcd <name>` | `cd $(git wt path <name>)` | cd into a worktree |
| `wto` | `cd $(git wt origin)` | cd into the origin (main) repo |
| `wtn [name]` | `git wt new` + `cd` | Create worktree and cd into it |
| `wtls` | `git wt list` | List worktrees |
| `wtla` | `git wt list-all` | List all worktrees |
| `wtrm <name>` | `git wt rm` | Remove a worktree |
| `wtopen <name>` | `git wt open` | Open worktree in editor |
| `wtclean` | `git wt clean` | Remove all worktrees |
| `wtpath <name>` | `git wt path` | Print worktree path |

Tab completion is included for bash and zsh — worktree names autocomplete for `wtcd`, `wtrm`, `wtopen`, and `wtpath`.

### Copying `.env` files

Worktrees are separate directories — your `.env` files (gitignored) won't be there.
Expand Down
77 changes: 77 additions & 0 deletions aliases/git-wt.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# git-wt shell aliases & functions
# Source this file in your .bashrc / .zshrc:
# source ~/.git-wt/git-wt/aliases/git-wt.sh
# — or wherever you keep this file —

# cd into a worktree by name
# wtcd my-feature
wtcd() {
local path
path=$(git wt path "$1" 2>/dev/null) || { echo "error: worktree '$1' not found" >&2; return 1; }
cd "$path" || return 1
}

# cd into the origin (main) repo from any worktree
# wto
wto() {
local path
path=$(git wt origin 2>/dev/null) || { echo "error: not in a git repo" >&2; return 1; }
cd "$path" || return 1
}

# Create a new worktree and cd into it
# wtn my-feature
# wtn (auto-generated name)
# wtn -b main hotfix
wtn() {
local output
output=$(git wt new "$@") || return 1
echo "$output"
local path
path=$(echo "$output" | grep 'Path:' | awk '{print $2}')
[[ -n "$path" ]] && cd "$path" || return 1
}

# List worktrees (current repo)
alias wtls='git wt list'

# List all worktrees (all repos)
alias wtla='git wt list-all'

# Remove a worktree
alias wtrm='git wt rm'

# Open worktree in editor
alias wtopen='git wt open'

# Remove all worktrees for current repo
alias wtclean='git wt clean'

# Print worktree path (for scripting)
alias wtpath='git wt path'

# --- Completions for aliases ---
if [[ -n "${ZSH_VERSION:-}" ]]; then
# zsh: reuse git-wt completions for worktree-name arguments
_wtcd() { compadd -- $(git wt _names 2>/dev/null); }
_wtn() { _arguments '*:branch:_git_branch_names'; }
_wtrm() { compadd -- $(git wt _names 2>/dev/null); }
_wtopen() { compadd -- $(git wt _names 2>/dev/null); }
_wtpath() { compadd -- $(git wt _names 2>/dev/null); }

compdef _wtcd wtcd
compdef _wtrm wtrm
compdef _wtopen wtopen
compdef _wtpath wtpath
elif [[ -n "${BASH_VERSION:-}" ]]; then
# bash
_wt_alias_complete() {
local cur="${COMP_WORDS[COMP_CWORD]}"
COMPREPLY=( $(compgen -W "$(git wt _names 2>/dev/null)" -- "$cur") )
}

complete -F _wt_alias_complete wtcd
complete -F _wt_alias_complete wtrm
complete -F _wt_alias_complete wtopen
complete -F _wt_alias_complete wtpath
fi
67 changes: 67 additions & 0 deletions aliases/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#!/usr/bin/env bash
# git-wt aliases installer
# Usage: curl -fsSL https://raw.githubusercontent.com/kuderr/git-wt/main/aliases/install.sh | bash

# shellcheck disable=SC2059 # intentional: ANSI color codes in printf format strings
set -euo pipefail

REPO="kuderr/git-wt"
BRANCH="main"
URL="https://raw.githubusercontent.com/${REPO}/${BRANCH}/aliases/git-wt.sh"
INSTALL_DIR="${HOME}/.local/share/git-wt"
INSTALL_PATH="${INSTALL_DIR}/aliases.sh"

# Colors
if [[ -t 1 ]] && [[ -z "${NO_COLOR:-}" ]]; then
GREEN=$'\033[0;32m' DIM=$'\033[2m' BOLD=$'\033[1m' RESET=$'\033[0m'
else
GREEN='' DIM='' BOLD='' RESET=''
fi

# Download helper
download() {
if command -v curl &>/dev/null; then
curl -fsSL "$1"
elif command -v wget &>/dev/null; then
wget -qO- "$1"
else
echo "Error: curl or wget required" >&2
exit 1
fi
}

echo ""
printf "${BOLD}Installing git-wt aliases...${RESET}\n\n"

# Download aliases file
mkdir -p "$INSTALL_DIR"
download "$URL" > "$INSTALL_PATH"
printf " ${GREEN}✓${RESET} Downloaded aliases to %s\n" "$INSTALL_PATH"

# Detect shell rc file
if [[ "${SHELL:-}" == *"zsh"* ]]; then
RC_FILE="${HOME}/.zshrc"
elif [[ "${SHELL:-}" == *"bash"* ]]; then
RC_FILE="${HOME}/.bashrc"
else
RC_FILE=""
fi

# Add source line if not already present
if [[ -n "$RC_FILE" ]]; then
if [[ -f "$RC_FILE" ]] && grep -qF "$INSTALL_PATH" "$RC_FILE" 2>/dev/null; then
printf " ${GREEN}✓${RESET} Already sourced in %s\n" "$RC_FILE"
else
printf '\n# git-wt aliases\nsource "%s"\n' "$INSTALL_PATH" >> "$RC_FILE"
printf " ${GREEN}✓${RESET} Added source line to %s\n" "$RC_FILE"
fi
else
echo ""
printf " Add to your shell profile:\n"
printf " ${DIM}source \"%s\"${RESET}\n" "$INSTALL_PATH"
fi

echo ""
printf "${GREEN}Done!${RESET} Restart your shell or run:\n"
printf " ${DIM}source \"%s\"${RESET}\n" "$INSTALL_PATH"
echo ""
12 changes: 12 additions & 0 deletions skills/git-wt/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,18 @@ Use `git wt adopt` when:
- A worktree was created with `git worktree add` and you want git-wt to manage it
- You want the worktree moved to `~/.git-wt/` for consistent management

## Shell Aliases

Optional `aliases/git-wt.sh` provides shorter commands. Source it in `.bashrc`/`.zshrc`:

| Alias | What it does |
|-------|-------------|
| `wtcd <name>` | `cd` into a worktree |
| `wto` | `cd` to the origin (main) repo |
| `wtn [name]` | Create worktree + `cd` into it |
| `wtls` / `wtla` | List / list-all |
| `wtrm` / `wtopen` / `wtclean` / `wtpath` | Shorthand for corresponding commands |

## Workflow: Parallel Agent Isolation

```bash
Expand Down