# How to Read git worktree list Output

_`git worktree list` prints one line per worktree: its path, the commit it has checked out, and its branch. `-v` adds the reason behind `locked` and `prunable`, and `--porcelain` gives scripts a stable format._

## The Fix

Run it from the main checkout or from any linked worktree. The output is the same:

```bash
git worktree list
```

Git 2.43 prints the main worktree first, then each linked worktree:

```text
/src/repo          1484765 [main]
/src/repo-feature  1484765 [feature]
/src/repo-gone     1484765 [gone] prunable
/src/repo-hotfix   1484765 [hotfix] locked
/src/repo-review   1484765 (detached HEAD)
```

Each column has one job:

| Column | Meaning |
|---|---|
| Path | The worktree's directory on disk |
| Commit | The abbreviated commit its `HEAD` points to |
| `[branch]` | The branch checked out there, or `(detached HEAD)` when there is none |
| `locked` | `git worktree prune`, `move` and `remove` skip it until you run `git worktree unlock` |
| `prunable` | Its directory is gone, and `git worktree prune` will drop its record |

Add `-v` to see why a worktree is locked or prunable:

```text
/src/repo-gone     1484765 [gone]
	prunable: gitdir file points to non-existent location
/src/repo-hotfix   1484765 [hotfix]
	locked: on external drive
```

The lock reason is the text you passed to `git worktree lock --reason`.

## Use It in Scripts

The default format is for people to read. `--porcelain` prints one attribute per line and a blank line between worktrees, and the Git documentation promises it stays stable:

```text
worktree /src/repo-hotfix
HEAD 1484765a6fd7fb36b364cc9a5ee79dcbe83e9dfe
branch refs/heads/hotfix
locked on external drive

worktree /src/repo-review
HEAD 1484765a6fd7fb36b364cc9a5ee79dcbe83e9dfe
detached
```

Find the directory where a branch is checked out:

```bash
git worktree list --porcelain \
  | awk '/^worktree /{p=substr($0,10)} $0=="branch refs/heads/feature"{print p}'
```

```text
/src/repo-feature
```

Add `-z` to end each line with a NUL byte instead of a newline. Use it when a worktree path can contain a newline.

## Why a Worktree Shows Up as prunable

Git keeps a record for each linked worktree in `.git/worktrees/`. If you delete the directory with `rm -rf`, the record stays, and `list` flags it `prunable`. Run `git worktree prune` to drop it, or `git worktree remove ` next time so Git deletes both. [Prune or delete a Git worktree](./prune-or-delete-worktree.md) shows both commands.

A stale record also keeps its branch reserved. Adding that branch in a new worktree fails until you prune:

```text
fatal: 'gone' is already used by worktree at '/src/repo-gone'
```

## How Treq Handles It

Treq tracks its own [workspaces](/docs/concepts/workspaces) under `.treq/workspaces/` instead of Git worktrees. Run `treq st` from the home repository to list every workspace with its stacked parent, uncommitted changes and commit count. The [CLI reference](/docs/reference/cli) covers the full output.

## Sources

- [git-worktree documentation](https://git-scm.com/docs/git-worktree#_list_output_format)

## Related

- [How to use git worktree add](./git-worktree-add.md)
- [Fix "branch is already used by worktree"](./branch-already-used-by-worktree.md)
- [What are Git Worktrees?](/learn/concepts/git/git-worktrees)
