In short: jj takes the named workspaces (default: the current one), warns about names it doesn't know,
and in one transaction removes each from the view, abandoning its working-copy commit if that commit
is empty with no description, a head, and not used by a bookmark, tag or other workspace. The
operation is forget workspace <name>. Afterwards it disconnects any Git worktree the
workspaces had.
The command is cmd_workspace_forget. To also delete the
directory, use jj workspace remove.
Workspaces are created with jj workspace add.
1. Command-line surface
| Argument | Type | Default | Meaning |
|---|---|---|---|
WORKSPACES (positional, repeatable) | workspace names | the current workspace | Which workspaces to forget (source). |
2. Configuration
None specific. The Git worktree step runs git as a subprocess, so git.executable-path
applies (source).
3. End-to-end flow
The workspace store keeps the forgotten workspace's path on purpose: jj undo restores the
workspace in the view, and it can only be found on disk again if the path is still recorded. A stale entry
is ignored for workspaces not in the view, and overwritten if the name is reused
(source).
4. Core architecture touchpoints
- View:
View::remove_workspacedrops the workspace's working-copy commit ID and its recorded GitHEAD. See the view page. - Abandoning:
MutableRepo::remove_workspacefirst callsmaybe_abandon_wc_commit, the same rulejj editandjj newuse when leaving a working-copy commit. - Working copy: untouched. If the current workspace is forgotten, jj says so after the transaction (§7).
- Git: a colocated secondary workspace is a Git worktree; forgetting it unlinks the
worktree, but failures are only warnings because the workspace is already gone
(
unlink_git_worktree).
5. Transaction and operation
- Transaction: one for all names, so
jj undorestores all of them at once (source). - Operation description:
forget workspace <name>, orforget workspaces <a>, <b>(source). - Commits: possibly abandoned working-copy commits. Only heads are abandoned, so nothing needs rebasing.
6. Algorithm and invariants
Workspaces are removed one at a time inside the transaction, so when several workspaces share a working-copy commit and are all forgotten together, the last one removed finds no other workspace using it, and the commit is abandoned (test).
Invariants: nothing on disk changes except Git worktree bookkeeping. Commits with content or a description are never abandoned.
7. Errors and edge cases
| Message | When | Source |
|---|---|---|
Warning: No such workspace: <name> | A name not in the view; the others are still forgotten. | forget.rs, test |
Nothing changed. | No known names. | forget.rs |
Warning: The current workspace '<name>' no longer exists after this operation. The working copy was left untouched., hint to jj undo | The current workspace was forgotten. | cli_util.rs, test |
Workspace `default` doesn't have a working-copy commit | Later, using @ in a forgotten workspace. | test |
8. Worked example
From upstream's test_default has a file in its working-copy commit; second, third and
fourth all share one empty commit. Forgetting default keeps its commit (it has
content), forgetting second keeps the shared one (still used), and forgetting third
and fourth together abandons it:
Upstream's final log (source):
○ 006bd1130b84
◆ 000000000000