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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@ source /path/to/git-wt/aliases/git-wt.sh
| `wto` | `cd $(git wt origin)` | cd into the origin (main) repo |
| `wtn [name]` | `git wt new` + `cd` | Create worktree and cd into it |
| `wtco <branch>` | `git wt checkout` + `cd` | Checkout existing branch and cd into it |
| `wtbye` | `git wt rm` + `cd origin` | Remove current worktree and cd to origin |
| `wtls` | `git wt list` | List worktrees |
| `wtla` | `git wt list-all` | List all worktrees |
| `wtrm <name>` | `git wt rm` | Remove a worktree |
Expand Down
31 changes: 31 additions & 0 deletions aliases/git-wt.sh
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,37 @@ wtco() {
[[ -n "${wt_path:-}" ]] && cd "$wt_path" || return 1
}

# Remove current worktree and cd back to origin
# wtbye
wtbye() {
local origin
origin=$(git wt origin 2>/dev/null) || { echo "error: not in a git repo" >&2; return 1; }

local cwd
cwd=$(pwd -P)

if [[ "$cwd" == "$origin" || "$cwd" == "$origin/"* ]]; then
echo "error: already in origin repo, not in a worktree" >&2
return 1
fi

local wt_home="${GIT_WT_HOME:-${HOME}/.git-wt}"
local repo_name
repo_name=$(basename "$origin")
local wt_root="${wt_home}/${repo_name}"

if [[ "$cwd" != "${wt_root}/"* ]]; then
echo "error: not in a git-wt managed worktree" >&2
return 1
fi

local wt_name="${cwd#"${wt_root}/"}"
wt_name="${wt_name%%/*}"

cd "$origin" || return 1
git wt rm "$wt_name"
}

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

Expand Down