Jujutsu: Managing workspaces
One of my favorite features in Jujutsu is its native support for workspaces (similar to Git worktrees). They let you have multiple working copies of the same repo, which is super handy for running tests in the background while you keep coding, or for juggling multiple features without constantly switching contexts.
While the built-in jj workspace commands are great, they can be a bit verbose. I use a few simple conventions and aliases to speed things up and make my workflow smoother.
Your repository must have been initialized with Jujutsu version 0.38.0 or later. Older repositories will not have the necessary workspace metadata for the default workspace.1
Creating a workspace
This usually requires specifying a name and a path. I prefer a convention where my secondary workspaces are siblings of my default workspace directory, named with a suffix. Assuming your default workspace is at ~/project, I prefer the new workspace named foo to be at ~/project.foo.
# Get the path of the default workspace
repo_dir=$(jj workspace root --name default)
# Create the new workspace at the same level with a suffix
jj workspace add --name foo $repo_dir.foo
To simplify this, you can define a Jujutsu alias in ~/.config/jj/config.toml:
[aliases]
wa = [
'util', 'exec', '--', 'bash', '-c',
'jj workspace add --name $0 $(jj workspace root --name default).$0'
]
Then, you can simply run:
jj wa fooSwitching between workspaces
If you have several active workspaces, it can be hard to remember their names or paths.
# List all workspaces to find the one you want to switch to
jj workspace list
# Get the path of the workspace
ws_dir=$(jj workspace root --name foo)
# Change directory to the workspace
cd $ws_dir
You can combine the above with fzf to interactively select a workspace from the list.
To simplify this, you can define a Jujutsu alias in ~/.config/jj/config.toml:
[aliases]
wo = [
'util', 'exec', '--', 'bash', '-c',
'jj workspace root --name $(jj workspace list | fzf | cut -d":" -f1)'
]
Then, you can explore and switch workspaces with a single command:
cd $(jj wo)Deleting a workspace
When you're done with a workspace, jj workspace forget stops tracking it in the repository. However, it leaves the files on disk. To clean up, you can combine it with rm -rf to delete the workspace directory.
# Forget the workspace
jj workspace forget --name foo
# Get the path of the default workspace
repo_dir=$(jj workspace root --name default)
# Remove the workspace directory
rm -rf $repo_dir.foo
To simplify this, you can define a Jujutsu alias in ~/.config/jj/config.toml:
[aliases]
wff = [
'util', 'exec', '--', 'bash', '-c',
'jj workspace forget $0 && rm -rf $(jj workspace root --name default).$0'
]
Then, you can simply run:
jj wff fooConclusion
Using a simple naming convention coupled with these aliases makes workspaces feel like a natural part of my workflow, not a chore. It lets me switch tasks instantly, helping me stay focused while keeping my work organized.
I've been using this approach with my jj aliases for a while, and it works great!